playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: The `--repeat-each` flag does not work with `--last-failed`

Open MeshyIce opened this issue 7 months ago • 2 comments

Version

latest

Steps to reproduce

  1. Run a test and make it fail (like by calling test.fail() on a test that should succeed
  2. Run npx playwright test --last-failed --repeat-each=10

Expected behavior

I expect to see the failed test(s) repeated 10 times, since I passed the --repeat-each=X flag.

Actual behavior

This is not the case, and it seems like the --repeat-each flag is ignored if the --last-failed flag is given.

Additional context

The use of these two flags together would really help in understanding if a test is flaky or not.

Environment

System:
    OS: macOS 15.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 2.73 GB / 36.00 GB
  Binaries:
    Node: 22.14.0 - ~/.local/share/nvm/versions/node/v22.14.0/bin/node
    npm: 11.3.0 - ~/.local/share/nvm/versions/node/v22.14.0/bin/npm
    pnpm: 10.11.0 - /opt/homebrew/bin/pnpm
    bun: 1.2.13 - /opt/homebrew/bin/bun
  IDEs:
    VSCode: 1.101.0 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash

MeshyIce avatar Jun 18 '25 17:06 MeshyIce

For anyone wondering on how to solve this, this is what I implemented in our CI:

# Add `|| true` as to not fail the Github CI on a failed test
bun run test --project=${{ matrix.browser }} --headed || true

bun run test --last-failed --list --pass-with-no-tests > failed-tests.txt
for test_name in $(awk -F ' › ' 'NF>1{print $2}' failed-tests.txt); do
    bun run test $test_name --repeat-each=10 --project=${{ matrix.browser }} --headed
done

I'll agree with anyone who says this is bad code, but it works :)

MeshyIce avatar Jun 18 '25 17:06 MeshyIce

Have you tried using Retries? That seems like what you're looking for.

Skn0tt avatar Jun 23 '25 08:06 Skn0tt

From the documentation: "failing tests will be retried multiple times until they pass". This does not help my case since it doesn't help me figure out how flaky is the test, which for that I'd want to retry the test multiple times independent of other executions.

MeshyIce avatar Jun 25 '25 15:06 MeshyIce