Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Handle async operations and prevent flaky tests
.claude/skills/testdriverai-testdriver-waiting-for-elements/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -31% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -21% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 0% | 0% |
| case-04 | ✗→✓ | ▲ Improved | -14% | 0% |
| case-07 | ✗→✓ | ▲ Improved | -28% | 0% |
<!-- Generated from waiting-for-elements.mdx. DO NOT EDIT. -->
By default, find() automatically polls for up to 10 seconds, retrying every 5 seconds until the element is found. This means most elements that appear after short async operations will be found without any extra configuration.
For longer operations, increase the timeout:
javascript// Default behavior - polls for up to 10 seconds automatically const element = await testdriver.find('Loading complete indicator'); await element.click(); // Wait up to 30 seconds for slower operations const element = await testdriver.find('Loading complete indicator', { timeout: 30000 }); await element.click(); // Useful after actions that trigger loading states await testdriver.find('submit button').click(); await testdriver.find('success message', { timeout: 15000 }); // Disable polling for instant checks const toast = await testdriver.find('notification toast', { timeout: 0 });
TestDriver automatically waits for the screen and network to stabilize after each action using redraw detection. This prevents flaky tests caused by animations, loading states, or dynamic content updates.
<Note> Redraw detection adds a small delay after each action but significantly reduces test flakiness. </Note>
For example, when clicking a submit button that navigates to a new page:
javascript// Click submit - TestDriver automatically waits for the new page to load await testdriver.find('submit button').click(); // By the time this runs, the page has fully loaded and stabilized await testdriver.assert('dashboard is displayed'); await testdriver.find('welcome message');
Without redraw detection, you'd need manual waits or retries to handle the page transition. TestDriver handles this automatically by detecting when the screen stops changing and network requests complete.
You can disable redraw detection or customize its behavior:
javascript// Disable redraw detection for faster tests (less reliable) const testdriver = TestDriver(context, { redraw: false });
Here is an example of customizing redraw detection:
javascript// Fine-tune redraw detection const testdriver = TestDriver(context, { redraw: { enabled: true, diffThreshold: 0.1, // Pixel difference threshold (0-1) screenRedraw: true, // Monitor screen changes networkMonitor: true, // Wait for network idle } });
wait()For simple pauses — waiting for animations, transitions, or state changes after an action — use wait():
javascript// Wait for an animation to complete await testdriver.find('menu toggle').click(); await testdriver.wait(2000); // Wait for a page transition to settle await testdriver.find('next page button').click(); await testdriver.wait(1000);
<Note> For waiting for specific elements to appear, prefer find() with a timeout option. Use wait() only for simple time-based pauses. </Note>
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-20 | pass→pass | 7,599 | 5,261 | -31% | 1 | 1 | 0% | 1,253 | 1,469 | +17% | 0 | 0 | — |
case-01 | fail→pass | 12,608 | 31,507 | +150% | 1 | 1 | 0% | 2,010 | 1,395 | -31% | 0 | 0 | — |
case-02 | fail→pass | 12,334 | 4,807 | -61% | 1 | 1 | 0% | 1,975 | 1,553 | -21% | 0 | 0 | — |
case-03 | fail→pass | 8,511 | 3,363 | -60% | 1 | 1 | 0% | 1,343 | 1,348 | +0% | 0 | 0 | — |
case-04 | fail→pass | 8,696 | 2,703 | -69% | 1 | 1 | 0% | 1,408 | 1,207 | -14% | 0 | 0 | — |
case-05 | pass→pass | 4,612 | 1,851 | -60% | 1 | 1 | 0% | 738 | 1,033 | +40% | 0 | 0 | — |
case-06 | pass→pass | 7,375 | 1,853 | -75% | 1 | 1 | 0% | 1,226 | 1,024 | -16% | 0 | 0 | — |
case-07 | fail→pass | 8,446 | 1,871 | -78% | 1 | 1 | 0% | 1,477 | 1,057 | -28% | 0 | 0 | — |
case-08 | pass→pass | 8,347 | 5,388 | -35% | 1 | 1 | 0% | 1,245 | 1,534 | +23% | 0 | 0 | — |
case-09 | pass→pass | 2,959 | 1,682 | -43% | 1 | 1 | 0% | 488 | 1,009 | +107% | 0 | 0 | — |
case-15 | fail→pass | 5,048 | 2,866 | -43% | 1 | 1 | 0% | 880 | 1,259 | +43% | 0 | 0 | — |
case-10 | fail→pass | 7,082 | 1,942 | -73% | 1 | 1 | 0% | 1,229 | 1,054 | -14% | 0 | 0 | — |
case-11 | pass→pass | 5,931 | 6,122 | +3% | 1 | 1 | 0% | 1,111 | 1,685 | +52% | 0 | 0 | — |
case-12 | fail→pass | 6,518 | 2,351 | -64% | 1 | 1 | 0% | 1,130 | 1,128 | -0% | 0 | 0 | — |
case-13 | fail→pass | 6,317 | 2,385 | -62% | 1 | 1 | 0% | 990 | 1,020 | +3% | 0 | 0 | — |
case-14 | fail→pass | 8,661 | 2,748 | -68% | 1 | 1 | 0% | 1,186 | 1,203 | +1% | 0 | 0 | — |
case-16 | pass→pass | 4,831 | 2,934 | -39% | 1 | 1 | 0% | 784 | 1,240 | +58% | 0 | 0 | — |
case-17 | pass→pass | 5,168 | 3,348 | -35% | 1 | 1 | 0% | 738 | 1,128 | +53% | 0 | 0 | — |
case-18 | fail→pass | 8,617 | 2,273 | -74% | 1 | 1 | 0% | 1,237 | 962 | -22% | 0 | 0 | — |
case-19 | pass→pass | 3,788 | 2,262 | -40% | 1 | 1 | 0% | 553 | 1,042 | +88% | 0 | 0 | — |
case-21 | fail→pass | 10,708 | 4,046 | -62% | 1 | 1 | 0% | 1,680 | 1,479 | -12% | 0 | 0 | — |
case-22 | pass→pass | 11,077 | 3,582 | -68% | 1 | 1 | 0% | 1,681 | 1,369 | -19% | 0 | 0 | — |
case-23 | pass→pass | 13,003 | 4,364 | -66% | 1 | 1 | 0% | 1,984 | 1,255 | -37% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +52 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.