Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Diagnose and fix flaky Playwright e2e tests. Use when tests fail intermittently, show timeout errors, have snapshot mismatches, or exhibit browser-specific failures.
.claude/skills/streamlit-fixing-flaky-e2e-tests/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-19 | ✗→✓ | ▲ Improved | 69% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 42% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 86% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 49% | 0% |
Diagnose and fix flaky Playwright E2E tests in e2e_playwright/.
TimeoutError: wait_until timed out)Run the script to identify the most flaky tests from recent CI runs:
bashuv run scripts/fetch_flaky_tests.py
Options:
--days N: Look back N days (default: 4)--top N: Return top N flaky tests (default: 10)--min-reruns N: Minimum total reruns to include (default: 2)--json: Output as JSON for programmatic useThe script downloads playwright_test_stats artifacts from successful playwright.yml runs and aggregates tests that required reruns.
Skip tests already marked with @pytest.mark.flaky---these are known flaky tests being tracked separately.
bash# Check if a test file has the flaky marker grep -l "pytest.mark.flaky" e2e_playwright/<test_file>.py
IMPORTANT: Only attempt to fix tests that fail locally. If you cannot reproduce the flakiness after 25 runs, do NOT attempt a fix—the test may be flaky due to CI environment factors that cannot be addressed locally.
Run the test up to 25 times with the affected browser(s). The loop breaks on first failure and captures full output:
bashfor i in {1..25}; do result=$(make run-e2e-test e2e_playwright/test_file.py::test_name -- --browser firefox 2>&1) if echo "$result" | grep -q "FAILED"; then echo "=== FAILURE ON RUN $i ===" echo "$result" break fi echo "Run $i: PASSED" done
If all 25 runs pass, skip this test and move to the next one.
After failure, examine:
e2e_playwright/test-results/ - traces, screenshots, videose2e_playwright/test-results/snapshot-updates/ - actual vs expected snapshotsFor persistent snapshot flakiness: If a test keeps failing due to snapshot mismatches, compare the actual vs expected images in e2e_playwright/test-results/snapshot-updates/. Look for:
This helps identify whether the flakiness is due to timing (content not loaded), animation state, or browser rendering differences.
Symptom: Screenshots taken before element fully renders, animations not complete.
Fix: Add explicit waits before interactions or screenshots:
python# Before element.click() assert_snapshot(element, name="snapshot") # After element.click() expect(element).to_be_visible() # Wait for visibility assert_snapshot(element, name="snapshot")
For popups/modals/calendars that animate:
pythoncalendar = page.get_by_test_id("stDateInputCalendar").first expect(calendar).to_be_visible() # Wait for animation to complete assert_snapshot(calendar, name="calendar-snapshot")
Symptom: Assertion expects exact count but gets more (e.g., assert 44 == 41).
Fix: Use >= instead of == when browsers may retry failed operations:
python# Before assert error_count == expected_count # After - browsers may retry failed image loads assert error_count >= expected_count
Symptom: TimeoutError on slower browsers.
Fix: Increase timeout for operations that can be slow:
python# Before wait_until(app, lambda: check_condition(), timeout=10000) # After wait_until(app, lambda: check_condition(), timeout=20000)
Symptom: Snapshot mismatch for ... (X pixels difference).
Causes:
Fix: Ensure element is stable before screenshot:
pythonelement = page.locator(".my-element") expect(element).to_be_visible() # For elements with animations, wait for specific CSS state: expect(element).to_have_css("opacity", "1") assert_snapshot(element, name="snapshot")
For elements containing images, wait for images to be fully loaded and decoded:
pythonfrom e2e_playwright.shared.app_utils import wait_for_images_loaded element = page.locator(".my-element") wait_for_images_loaded(element) # Waits for load + decode assert_snapshot(element, name="snapshot")
| Browser | Common Issues | |---------|---------------| | Firefox | Slower console logging, may retry failed requests, subpixel rendering differences | | Webkit | May have timing differences with layout | | Chromium | Generally most reliable, use as baseline |
Symptom: Firefox screenshots flake with 1-pixel differences due to subpixel rendering variations.
Fix: Add a one-liner markdown element above the element being tested. This shifts the subpixel position to a more stable value:
python# In the test app (.py file) st.markdown("---") # Stabilizes subpixel rendering for elements below st.date_input("Pick a date")
This is a workaround for Firefox's subpixel rendering behavior and can reduce snapshot flakiness when other timing fixes don't help.
If you've exhausted timing fixes and the flakiness persists only on a specific browser due to known browser limitations (not test bugs), skip_browser may be appropriate as a last resort:
python# Only use after confirming this is a browser-level limitation, not a fixable timing issue @pytest.mark.skip_browser("webkit", reason="Webkit has known layout timing issues with this element") def test_problematic_on_webkit(app: Page): ...
Important: Using skip_browser requires justification. Prefer fixing the underlying timing issue first. See "Rules" section for guidance on when skipping is acceptable.
After applying fix, verify with multiple runs:
bash# Run 10+ times to ensure stability for i in {1..10}; do make run-e2e-test e2e_playwright/test_file.py::test_name -- --browser firefox 2>&1 | grep -E "(PASSED|FAILED)" done
Target: 10/10 passes before considering fix complete.
From e2e_playwright.conftest:
wait_for_app_run(page) - Wait for Streamlit script executionwait_for_app_loaded(page) - Wait for initial app loadwait_until(page, fn, timeout) - Poll until condition is trueFrom e2e_playwright.shared.app_utils:
expect_no_skeletons(element) - Wait for loading skeletons to disappearreset_focus(page) - Click outside to trigger blur eventsreset_hovering(locator) - Move mouse away from elementwait_for_images_loaded(element) - Wait for images to be loaded and decoded (important for webkit)uv run scripts/fetch_flaky_tests.py --top 10@pytest.mark.flakymake check before committingskip_browser is acceptable only when:reason explaining why| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-19 | fail→pass | 16,528 | 7,909 | -52% | 1 | 1 | 0% | 1,474 | 2,490 | +69% | 0 | 0 | — |
case-01 | fail→fail | 17,155 | 16,243 | -5% | 1 | 1 | 0% | 246 | 2,477 | +907% | 0 | 0 | — |
case-02 | fail→fail | 12,933 | 18,469 | +43% | 1 | 1 | 0% | 302 | 2,544 | +742% | 0 | 0 | — |
case-03 | fail→fail | 10,943 | 17,479 | +60% | 1 | 1 | 0% | 266 | 2,573 | +867% | 0 | 0 | — |
case-04 | fail→pass | 18,040 | 9,460 | -48% | 1 | 1 | 0% | 2,033 | 2,895 | +42% | 0 | 0 | — |
case-05 | fail→pass | 15,651 | 4,157 | -73% | 1 | 1 | 0% | 1,506 | 2,808 | +86% | 0 | 0 | — |
case-06 | fail→pass | 13,709 | 9,939 | -28% | 1 | 1 | 0% | 2,044 | 2,941 | +44% | 0 | 0 | — |
case-07 | fail→pass | 14,793 | 11,335 | -23% | 1 | 1 | 0% | 2,049 | 3,053 | +49% | 0 | 0 | — |
case-08 | fail→pass | 15,077 | 12,315 | -18% | 1 | 1 | 0% | 1,501 | 2,664 | +77% | 0 | 0 | — |
case-09 | fail→pass | 31,605 | 8,429 | -73% | 1 | 1 | 0% | 4,301 | 2,713 | -37% | 0 | 0 | — |
case-10 | pass→pass | 18,457 | 8,977 | -51% | 1 | 1 | 0% | 2,062 | 2,791 | +35% | 0 | 0 | — |
case-11 | fail→pass | 23,925 | 9,017 | -62% | 1 | 1 | 0% | 3,281 | 2,728 | -17% | 0 | 0 | — |
case-12 | fail→fail | 16,711 | 8,565 | -49% | 1 | 1 | 0% | 2,808 | 2,773 | -1% | 0 | 0 | — |
case-13 | fail→pass | 25,970 | 8,545 | -67% | 1 | 1 | 0% | 3,947 | 2,736 | -31% | 0 | 0 | — |
case-14 | fail→pass | 20,520 | 6,566 | -68% | 1 | 1 | 0% | 2,125 | 3,299 | +55% | 0 | 0 | — |
case-15 | fail→pass | 19,985 | 8,648 | -57% | 1 | 1 | 0% | 1,861 | 3,624 | +95% | 0 | 0 | — |
case-16 | pass→pass | 16,137 | 4,912 | -70% | 1 | 1 | 0% | 1,632 | 2,833 | +74% | 0 | 0 | — |
case-17 | pass→pass | 13,838 | 10,152 | -27% | 1 | 1 | 0% | 1,264 | 2,990 | +137% | 0 | 0 | — |
case-18 | pass→pass | 12,483 | 10,483 | -16% | 1 | 1 | 0% | 2,161 | 3,067 | +42% | 0 | 0 | — |
case-20 | pass→pass | 20,563 | 10,101 | -51% | 1 | 1 | 0% | 2,144 | 3,004 | +40% | 0 | 0 | — |
case-21 | pass→pass | 20,447 | 6,742 | -67% | 1 | 1 | 0% | 2,125 | 3,083 | +45% | 0 | 0 | — |
case-22 | fail→fail | 16,274 | 23,511 | +44% | 1 | 1 | 0% | 2,886 | 5,357 | +86% | 0 | 0 | — |
case-23 | pass→pass | 14,423 | 11,053 | -23% | 1 | 1 | 0% | 2,457 | 3,128 | +27% | 0 | 0 | — |
case-24 | fail→fail | 23,510 | 21,230 | -10% | 1 | 1 | 0% | 2,995 | 4,738 | +58% | 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. 24 cases were attempted, and 21 counted toward the lift figure. The other 3 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +46 percentage points is the difference between those two pass rates over the 21 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.