Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

fixing-flaky-e2e-tests修复不稳定的 e2e 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

288

周安装

12

GitHub Stars

44,429

下载量

96
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:fixing-flaky-e2e-tests(修复不稳定的 e2e 测试)
来源仓库:https://github.com/streamlit/streamlit
仓库路径:skills/fixing-flaky-e2e-tests
安装命令:
npx skills add https://github.com/streamlit/streamlit --skill fixing-flaky-e2e-tests
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/streamlit/streamlit --skill fixing-flaky-e2e-tests

简介

fixing-flaky-e2e-tests 用于辅助测试设计、自动化测试和回归验证。

  • 适合编写端到端测试或根据失败日志定位问题,整理测试计划。
  • 使用时需确认项目测试框架、运行命令和夹具数据,避免误改真实逻辑。
  • 涉及浏览器或外部服务时应区分本地模拟与生产环境。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Fixing flaky E2E tests

Diagnose and fix flaky Playwright E2E tests in e2e_playwright/.

When to use

  • Tests fail intermittently (pass sometimes, fail others)
  • Timeout errors (TimeoutError: wait_until timed out)
  • Snapshot mismatches with pixel differences
  • Browser-specific failures (firefox, webkit, chromium)
  • User asks to fix top flaky tests from CI

Finding top flaky tests

Run the script to identify the most flaky tests from recent CI runs:

uv 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 use

The script downloads playwright_test_stats artifacts from successful playwright.yml runs and aggregates tests that required reruns.

Filtering tests to fix

Skip tests already marked with @pytest.mark.flaky---these are known flaky tests being tracked separately.

# Check if a test file has the flaky marker
grep -l "pytest.mark.flaky" e2e_playwright/<test_file>.py

Investigation workflow

1. Reproduce the flakiness locally (REQUIRED)

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:

for 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.

2. Check test artifacts

After failure, examine:

  • e2e_playwright/test-results/ - traces, screenshots, videos
  • e2e_playwright/test-results/snapshot-updates/ - actual vs expected snapshots

For 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:

  • Pixel-level differences (use an image diff tool or overlay)
  • Subtle layout shifts, font rendering variations, or timing artifacts
  • Browser-specific rendering quirks (especially Firefox subpixel issues)

This helps identify whether the flakiness is due to timing (content not loaded), animation state, or browser rendering differences.

Common causes and fixes

Timing issues (most common)

Symptom: Screenshots taken before element fully renders, animations not complete.

Fix: Add explicit waits before interactions or screenshots:

# 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:

calendar = page.locator('[data-baseweb="calendar"]').first
expect(calendar).to_be_visible()  # Wait for animation to complete
assert_snapshot(calendar, name="calendar-snapshot")

Browser retry causing extra events

Symptom: Assertion expects exact count but gets more (e.g., assert 44 == 41).

Fix: Use >= instead of == when browsers may retry failed operations:

# Before
assert error_count == expected_count

# After - browsers may retry failed image loads
assert error_count >= expected_count

Timeout too short

Symptom: TimeoutError on slower browsers.

Fix: Increase timeout for operations that can be slow:

# Before
wait_until(app, lambda: check_condition(), timeout=10000)

# After
wait_until(app, lambda: check_condition(), timeout=20000)

Snapshot mismatch due to timing

Symptom: Snapshot mismatch for... (X pixels difference).

Causes:

  • Element still animating when screenshot taken
  • Font rendering not complete
  • Async content not loaded

Fix: Ensure element is stable before screenshot:

element = 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")

Browser-specific considerations

BrowserCommon Issues
FirefoxSlower console logging, may retry failed requests, subpixel rendering differences
WebkitMay have timing differences with layout
ChromiumGenerally most reliable, use as baseline

Firefox subpixel rendering flakiness

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:

# 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:

# 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.

Verification

After applying fix, verify with multiple runs:

# 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.

Key utilities

From e2e_playwright.conftest:

  • wait_for_app_run(page) - Wait for Streamlit script execution
  • wait_for_app_loaded(page) - Wait for initial app load
  • wait_until(page, fn, timeout) - Poll until condition is true

From e2e_playwright.shared.app_utils:

  • expect_no_skeletons(element) - Wait for loading skeletons to disappear
  • reset_focus(page) - Click outside to trigger blur events
  • reset_hovering(locator) - Move mouse away from element

Complete workflow

  1. Fetch flaky tests: uv run scripts/fetch_flaky_tests.py --top 10
  2. Filter out marked tests: Skip tests with @pytest.mark.flaky
  3. For each remaining test:

- Read the test code to understand what it's testing - Reproduce the flakiness locally (up to 25 runs) - Skip if not reproducible: If 25 runs all pass, move to the next test - Identify the root cause (timing, browser-specific, etc.) - Apply the minimal fix - Verify with 10+ runs on affected browser(s)

  1. Run checks: make check before committing

Rules

  • Reproduce locally first: Only fix tests you can reproduce locally (up to 25 runs)
  • Minimal fixes: Smallest change that fixes the issue
  • Don't disable tests without justification: Never skip tests just to "fix" flakiness. skip_browser is acceptable only when:

1. You've exhausted all timing/wait fixes 2. The flakiness is due to a documented browser limitation (not a test bug) 3. You include a clear reason explaining why

  • Verify thoroughly: Run 10+ times on affected browser after fix
  • Preserve test intent: Understand what the test is validating
  • Document cause: Add comments explaining why waits/timeouts are needed

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.52%
按下载量换算34

Claude

32.86%
按下载量换算32

Cursor

20.18%
按下载量换算19

Gemini CLI

9.11%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills