Skip to content

feat(test-runner): add --shuffle to run tests in random order - #42877

Merged
Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:fix-9297
Sep 23, 2026
Merged

Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:fix-9297

Conversation

@pavelfeldman

Copy link
Copy Markdown
Member

Summary

  • npx playwright test --shuffle [seed] randomizes the order in which test groups are dispatched: files, and individual tests in parallel mode. Serial suites and phase/dependency ordering are preserved.
  • The seed is printed in the "Running N tests" line and recorded in metadata.shuffleSeed; pass it back to reproduce the order.

Fixes #9297
Fixes #7040
Fixes #12512

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

8 flaky ⚠️ [installation tests] › playwright-test-package-managers.spec.ts:63 › pnpm: @playwright/test should work `@package-installations-macos-latest`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:179 › serviceWorker(), and fromServiceWorker() work `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:725 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/browsercontext-page-event.spec.ts:173 › should work with Ctrl-clicking `@realtime-time-library-chromium-linux`
⚠️ [chromium-library] › library/video.spec.ts:725 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:436 › should produce network events, routing, and annotations for Service Worker (advanced) `@chromium-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:257 › third party 'Partitioned;' cookies `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:470 › top level 'Partitioned;' cookie and same origin iframe `@firefox-ubuntu-22.04-node20`

52096 passed, 1241 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

3 failed
❌ [chromium] › mcp/cli-webmcp.spec.ts:162 › webmcp-call disambiguates duplicate tool names by frame @mcp-ubuntu-latest-chromium
❌ [chromium] › mcp/sse.spec.ts:196 › sse transport browser lifecycle (persistent) @mcp-ubuntu-latest-chromium
❌ [firefox] › mcp/annotate.spec.ts:446 › should switch screencast to -s session on show --annotate @mcp-windows-latest-firefox

8702 passed, 1474 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Hi, I'm the Playwright bot and I took a look at the red CI here.

🟢 All three MCP failures are pre-existing flakes — the PR is clear

Each one has a history of failing on other SHAs and PRs in the aggregated CI results, and none of them touch the code this PR changes: --shuffle is opt-in, so shuffleTestGroups() and the shuffleSeed metadata are never reached on a CI run that doesn't pass the flag.

Details

Pre-existing flake / infra

Why the diff can't reach them

The runner change is gated on configCLIOverrides.shuffle, which is only set by the new --shuffle flag; CI doesn't pass it, so test group ordering and the reporter's "Running N tests" line are byte-identical to main. The rest of the diff is docs, the CLI option declaration, and a new tests/playwright-test/shuffle.spec.ts — nothing the MCP suite loads.

Triaged by the Playwright bot - agent run

@yury-s Yury Semikhatsky (yury-s) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add it to api review items.

}

if (testRun.config.configCLIOverrides.shuffle)
shuffleTestGroups(phaseTestGroups, testRun.config.configCLIOverrides.shuffle);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests with beforeAll/afterAll can be placed in the same group and won't be shuffled with this approach. Maybe it's okay but perhaps you want to shuffle them too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Randomise test execution order [Feature] Run tests in a random order [Feature] Shuffle tests with a random order

2 participants