condition-based-waiting

Replace arbitrary delays with configurable condition-based polling in tests.

3|2|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/liauw-media/CodeAssist --skill condition-based-waiting-liauw-media
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/liauw-media/CodeAssist/tree/main/skills/testing/condition-based-waiting
Command: npx skills add https://github.com/liauw-media/CodeAssist --skill condition-based-waiting-liauw-media

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill eliminates flaky, unreliable tests caused by arbitrary sleep() or setTimeout() calls by replacing them with intelligent condition-based polling. This ensures tests pass consistently regardless of system speed, saving time and improving CI/CD reliability.

Core Features & Use Cases

  • Reliable Condition Polling: Provides a generic waitForCondition function to poll for specific conditions (e.g., element visibility, API response, state change) rather than guessing with fixed delays.
  • Flaky Test Prevention: Makes tests robust against timing variations, preventing intermittent failures that waste CI/CD resources and developer time.
  • Use Case: Instead of await sleep(2000) after clicking a submit button, this skill guides you to await waitForElement('#success-message'), ensuring the test only proceeds when the success message is actually visible, making it reliable on both fast and slow systems.

Quick Start

I have an end-to-end test that intermittently fails because an element isn't visible yet. Use the condition-based-waiting skill to fix it.

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 timing issues?

Replace arbitrary sleep() or setTimeout() calls with condition-based waiting that polls for specific conditions like element visibility or state changes. This ensures tests pass consistently regardless of system speed, eliminating intermittent failures from race conditions and timing variations.

What's the best way to handle asynchronous operations in end-to-end tests?

Use condition-based waiting to verify that expected conditions are met before proceeding, rather than guessing fixed delays. Poll for element visibility, API responses, or state changes to make tests robust against timing variations on both fast and slow systems.

How do I wait for an element to appear in an automation test?

Condition-based waiting provides helper functions like waitForElement that poll until an element is visible or exists in the DOM. Instead of sleep(2000), call waitForElement('#selector') to proceed only when the element is actually ready.

Can I use condition polling to verify event counts in tests?

Yes. The waitForEventCount helper function polls until a specified number of events have occurred, letting you verify event behavior reliably without hardcoded delays or race condition failures.

Why do tests with sleep() calls fail intermittently?

Fixed delays don't account for system speed variations. On slower systems the delay is too short; on faster systems it wastes time. Condition-based waiting eliminates these failures by proceeding only when the actual condition is true.

Does condition-based waiting work with pattern matching on events?

Yes. The waitForEventMatch function enables polling for events that match specific criteria, allowing reliable verification of event data and behavior without timing guesses.