When working with automated testing, one of the most common and time-saving features developers need is the ability to rerun only the tests that failed. Playwright makes this easy with the --last-failed flag.
Here’s how it works and why you should start using it.
--last-failed
The --last-failed flag tells Playwright Test to only rerun tests that failed in the previous run. This is incredibly useful when:
- You're debugging a flaky or failing test.
- You're working on a fix and want to recheck only the broken tests.
- You’re saving time and want fast feedback.
How to implement re-run last failed test
Just run following command.
npx playwright test test.spec.js --last-failed
Note: If all tests pass on the next run, the failure cache is cleared. So if you run --last-failed again, nothing will run.
Limit failures and fail fast
You can limit the number of failed tests in the whole test suite by setting maxFailures config option or passing --max-failures command line flag.
When running with "max failures" set, Playwright Test will stop after reaching this number of failed tests and skip any tests that were not executed yet. This is useful to avoid wasting resources on broken test suites.
Passing command line option:
npx playwright test --max-failures=10
Setting in the configuration file:
playwright.config.ts
import { defineConfig } from '@playwright/test'; export default defineConfig({ // Limit the number of failures on CI to save resources maxFailures: process.env.CI ? 10 : undefined, });
No comments:
Post a Comment