condition-based-waiting

Replace arbitrary timeouts in tests with condition polling for state changes.

Updated Jan 9, 2026
One-click install
npx skills add https://github.com/maplin-co/ai-course --skill condition-based-waiting-maplin-co
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/maplin-co/ai-course/tree/main/.opencode/skill/condition-based-waiting
Command: npx skills add https://github.com/maplin-co/ai-course --skill condition-based-waiting-maplin-co

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the common issue of flaky tests caused by arbitrary timeouts and race conditions, ensuring more reliable test suites.

Core Features & Use Cases

  • Replaces Arbitrary Timeouts: Swaps setTimeout or sleep with condition polling.
  • Waits for Actual State Changes: Ensures tests proceed only when the desired condition is met.
  • Use Case: In an e-commerce test suite, instead of waiting a fixed 5 seconds for a product to appear in the cart, this Skill would poll the cart's item count until it's greater than zero, making the test robust regardless of server load.

Quick Start

Use the condition-based-waiting skill to wait for the element with id 'user-profile' to be visible on the page.

Frequently Asked Questions about condition-based-waiting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix flaky tests caused by arbitrary timeouts and race conditions?

Condition polling replaces fixed delays by repeatedly checking for a specific state change, such as an element becoming visible or an item count updating, ensuring tests proceed only when the condition is met.

How do I replace setTimeout or sleep with condition polling in automated testing?

You replace setTimeout or sleep by implementing a polling mechanism with configurable timeouts that repeatedly evaluates a condition, such as cart item count exceeding zero, and proceeds only when that condition is satisfied.

What is the best way to wait for actual state changes in UI automation?

The best approach is condition polling, which evaluates desired states repeatedly within a configurable timeout window and proceeds only upon success, avoiding arbitrary delays that cause inconsistent pass/fail behavior.

Can I configure polling timeouts and error reporting for unmet conditions?

Yes, this approach requires a polling mechanism with configurable timeouts to define the maximum wait duration and generates clear error reporting when conditions remain unmet, ensuring robust test failure visibility.

When should I use condition polling instead of arbitrary timeouts in test suites?

Use condition polling in scenarios involving race conditions, timing dependencies, or inconsistent pass/fail behavior, where server load or network latency makes fixed delays unreliable for waiting on state changes.

Why do my automated tests fail intermittently due to timing dependencies?

Tests fail intermittently because arbitrary timeouts guess timing rather than verifying state. Condition polling eliminates this by waiting for actual state changes, ensuring tests proceed only when conditions are truly met.