wait-strategy
Skill1 starsChanged 3 months agoMITView on GitHub
Use when making any test wait reliably, fixing a flaky/timing-dependent test, or deciding how to wait for navigation, a response, an element, or a form commit. The single most important anti-flake skill.
In this repository23 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- ai-native-workflowSkill
- api-testingSkill
- bootstrapSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- page-objectsSkill
- salesforce-authSkill
- salesforce-dataSkill
- salesforce-locatorsSkill
- salesforce-metadata-contractSkill
- salesforce-personasSkill
- salesforceSkill
- salesforce-waitsSkill
- security-testingSkill
- selectorsSkill
- test-standardsSkill
- type-safetySkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
If you keep a networkidle, leave an inline comment saying _why this page goes quiet_.
- Very specific: line 110
If actionTimeout ≥ the test timeout it can never fire, and you're back to the useless generic message.
- Very specific: line 142
Only for a non-network animation with no DOM/network signal, with a // TODO and a tracking ticket.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Wait Strategy — Zero Timeouts, Zero networkidle
The #1 source of flake is bad waits. This scaffold uses deterministic waits only.
One hard ban, one strong default
page.waitForTimeout(ms)— BANNED (ESLint error). A blind sleep is either too short (flake) or too long (slow). Never a primary wait.page.waitForLoadState('networkidle')— DISCOURAGED, not banned (ESLint warns). It resolves after 500 ms of network silence. The key question is: does this page ever go quiet?
When networkidle is the WRONG tool (the common case)
On a chatty SPA — React with polling, and especially Salesforce Lightning (Aura server actions, CometD long-poll, batched /aura XHRs, beacons) — the network is never quiet for 500 ms. The wait either hangs to timeout or resolves in a random gap between requests. It is non-deterministic there. Replace it with a pre-registered response wait or a web-first assertion.
When networkidle is legitimately FINE
- Static / server-rendered pages with no background polling — a classic multi-page site's initial load that fires a burst of requests then genuinely settles.
- Exploration / debugging (remove before committing).
- A page where you must wait for an unknown burst of parallel resource loads to settle AND you've confirmed there's no recurring poll.
If you keep a networkidle, leave an inline comment saying why this page goes quiet.
On the
salesforceprofilenetworkidleis a hard REFUSAL (Constitution #2), not a discouragement — and/auracannot be waited on by URL either, because every Aura action batches through one endpoint. Loadsalesforce-waitsfor what to wait on instead (ui-apipaths, toasts, spinners, inline edit).
Opinions on
networkidlediffer (some ban it outright, some call it "acceptable but not preferred"). The truth is profile-dependent: harmful on SPAs, fine on static pages. Default to deterministic waits and reach fornetworkidleonly when you can name why the page settles.
The hierarchy — use the first that applies
- Wait for the specific gating response —
waitForRest/waitForGraphQLinhelpers/util/network.ts. Use when a network call gates the next step. - Web-first assertion on a DOM signal —
toBeVisible,toBeHidden,toBeEnabled,toHaveValue,toContainText. Playwright auto-retries these until the timeout. This is the default for "is the screen ready?". waitForURL— for navigations.
THE GOLDEN RULE — pre-register before you trigger
page.waitForResponse(...) only catches responses arriving after it is called. Click-first, wait-second misses fast responses and times out silently.
// ✅ arm, trigger, await
const loaded = waitForRest(page, '/api/products'); // 1
await searchButton.click(); // 2
await loaded; // 3
// ❌ misses an already-arrived response
await searchButton.click();
await waitForRest(page, '/api/products');Concurrent requests → arm both, then Promise.all:
const a = waitForRest(page, '/api/cart');
const b = waitForGraphQL(page, 'UpdateCartTotals');
await option.click();
await Promise.all([a, b]);Blur after fill — commit the dirty flag
Controlled-form components (React Hook Form, Formik, Lightning inputs) often only mark the form dirty / valid on blur, not on keystroke. If Save stays disabled after a fill(), that's why. Use fillAndBlur (helpers/util/forms.ts), then assert the value committed.
The loader trap — partial-match CSS-module classes
page.locator('.loader') matches zero elements when the class is hashed (loader__a1b2c), and toBeHidden() on zero elements passes trivially — a false green. Use [class*="loader"] (partial) or, better, a data-testid. BasePage.waitForHidden already calls .first().
The timeout budget — fail fast, and fail DIAGNOSABLY
Playwright's actionTimeout defaults to 0: no timeout at all. So an un-clickable element does not
fail on its own — it spins until the whole TEST times out, and you get:
Test timeout of 30000ms exceeded. ← tells you nothingWith actionTimeout set (playwright.config.ts), the same failure reports:
locator.click: Timeout 10000ms exceeded.
waiting for locator('button[name="Save"]')
- locator resolved to <button disabled>…</button>
- element is not enabled ← names the element AND the failed checkThat's the real reason to bound it. Speed is the bonus; diagnosability is the point.
What click() is actually waiting for (actionability)
- attached to the DOM
- visible
- stable (not animating)
- receives pointer events — not covered by another element
- enabled
#4 is what hangs in practice. The element is right there and visible, but permanently under a toast, a modal backdrop, a sticky header, or a spinner overlay that never cleared. Playwright retries silently and only tells you at timeout. If a click times out on a visible, enabled element, suspect an overlay first — and fix the missing wait, not the timeout.
The ordering invariant
actionTimeout < expect.timeout × (a few retries) < test timeoutIf actionTimeout ≥ the test timeout it can never fire, and you're back to the useless generic
message. Keep a wide gap so the specific error always wins the race.
Current budget
| Setting | Generic | Salesforce | Why |
actionTimeout | 10s | 15s | one interaction; longer means something is wrong |
navigationTimeout | 20s | 30s | page loads legitimately exceed a click |
expect.timeout | 7s | 7s | per web-first assertion, and they retry |
| test timeout | 45s (e2e 120s) | 90s | above action+navigation so the specific error wins |
globalTimeout | 30 min (CI) | — | one hung worker must not burn the CI allowance |
Lightning gets more headroom because Aura hydration and the record-page bootstrap are genuinely slow. That's a fact about the platform, not a concession — squeezing it produces false failures, which teaches people to ignore timeouts.
Note the e2e row: the TEST budget grows, the per-ACTION budget does not. A single click should never take longer in a journey than in a functional test; only the number of clicks changes.
Needing more time is a local decision, never a global one
Raising a global timeout to green a red test is Constitution #13 — silencing a failure. If one test is legitimately slow, say so at that test:
test.slow(); // triples this test's timeout — built in, for known-slow tests
test.setTimeout(120_000); // explicit; requires a comment justifying itWhen waitForTimeout is grudgingly acceptable
Only for a non-network animation with no DOM/network signal, with a // TODO and a tracking ticket. Treat as a smell.
Checklist
- No
waitForTimeout. - No
networkidleon an SPA; any kept use is on a static page with an explaining comment. - Every response wait is pre-registered before its trigger.
- Screen-readiness uses a web-first assertion, not a sleep.
- Loader waits use partial-match or testid +
.first(). - Save-after-fill flows blur to commit the dirty flag.
- No timeout was RAISED to make a failure go away (#13). Slow-by-nature tests use
test.slow().
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

