In Playwright (a Node.js library for browser automation), the flags --repeat-each and --only-changed are used with the Playwright Test Runner (npx playwright test) to control how tests are run. Here's what each one does:
--repeat-each <N>
This flag repeats each test a specified number of times. If You want to verify the stability of your tests by running them multiple times.
npx playwright test test.spec.js --repeat-each 5
This command runs each individual test 5 times, even if they pass each time.
1. Stress Test with More Workers
Sometimes, running the test repeatedly isn’t enough, especially if the failure is triggered by CPU or memory constraints on CI. In this case, you can stress your system by maximizing the number of workers:
npx playwright test test.spec.js --repeat-each 100 --workers=10
2. Stop on First Failure
Running a test 100 times can take a while, but you don’t have to wait for all runs to complete. Use the -x flag to stop execution as soon as a failure occurs:
npx playwright test test.spec.js --repeat-each 100 -x
This will save you time by immediately identifying when a test starts failing under stress.
--only-changed
This flag runs only the tests related to changed files (based on git changes). If You want to save time during development by only running tests related to files you've recently modified.
npx playwright test test.spec.js --only-changedThis command will:
- Detect changed test files or changed files they depend on.
- Run only the affected tests.
Also we can run only changed tests and repeat each one twice.
npx playwright test test.spec.js --only-changed --repeat-each 2
This is all about checking flaky test in playwright.
No comments:
Post a Comment