condition-based-waiting

Replace arbitrary timeouts with condition polling in automated tests.

2|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/ucirello/sgai --skill condition-based-waiting-ucirello
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/ucirello/sgai/tree/main/cmd/sgai/skel/.sgai/skills/condition-based-waiting
Command: npx skills add https://github.com/ucirello/sgai --skill condition-based-waiting-ucirello

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, replacing them with precise condition polling for reliable test execution.

Core Features & Use Cases

  • Replaces arbitrary timeouts: Eliminates setTimeout or sleep in tests.
  • Waits for actual state changes: Polls for specific conditions to be met.
  • Use Case: Fix tests that intermittently fail due to timing issues by waiting for a UI element to become visible or an API response to contain specific data, rather than guessing how long it will take.

Quick Start

Use the condition-based waiting skill to wait for the condition that the user count is greater than 5.

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 race conditions and arbitrary timeouts?

Fix flaky tests by replacing arbitrary timeouts with condition polling. This approach waits for specific state changes, such as UI visibility or API data, ensuring deterministic outcomes rather than relying on guessed sleep durations.

What is condition polling in automated testing?

Condition polling is a technique that checks for specific conditions to be met before proceeding. It uses a callback function with a timeout to eliminate timing dependencies and solve race conditions in automated frameworks.

How do I wait for an API response to contain specific data in test automation?

Wait for API data by implementing a generic polling function that accepts a condition callback and timeout. This ensures the test only proceeds once the response contains the required data, preventing intermittent failures.

What's the best way to eliminate sleep and setTimeout from automated tests?

Eliminate sleep and setTimeout by replacing them with condition-based waiting. This method polls for actual state changes using a condition callback, providing reliable test execution without arbitrary delays.

Do I need a specific testing framework to use condition-based waiting?

No specific framework is required, but you need a generic polling function. This function must accept a condition callback, a description, and a timeout parameter to integrate with your existing automated testing setup.

Why does my automated test intermittently fail due to timing issues?

Tests intermittently fail due to timing dependencies and race conditions when using arbitrary timeouts. Replacing static waits with condition polling ensures tests wait for actual state changes, achieving deterministic outcomes.