Sponsored Link
Looking for a unified way to  viewmonitor, and  debug Playwright Test Automation runs?
Try the Playwright Dashboard by today. Use the coupon code PWSOL10 for a 12 month 10% discount.

How To Run Failures Only From The Last Playwright Run Via CLI

Hello Playwright 1.44 release! With this release we now have official support to run failures only from the last playwright run.

💡
TLDR; npx playwright test--last-failed

Previous Solution

Last year I created the json summary reporter and a bash script that can be found in the article below. This was my work around for being able to re-run failures easily. I still think there is a lot of value in the tools that I created, specifically when I have failures in CI, I can quickly copy my json summary results and paste them in my local summary.json file, and run failrues locally to debug. See the below article to find out more.

What’s the easiest way to only re-run failures after the Playwright Tests are finished?
Out of all the wonderful features that the Playwright Test Runner has around retrying failures, one thing I found myself needing was an easy way to re-run all the tests from a recent run. This is different than test retry and assert retry in that those are completing retries within

Current Solution

But what is really exciting is I can now use this new command from the CLI to re-run the failed tests from my last run. First thing you need to ensure, is that your playwright version is at least 1.44. You can check this by visiting your package.json.

For this example I've created some flakey tests that will fail half of the time to help demonstrate this feature. After running npx playwright test I see these results.

I can now run the command npx playwright test --last-failed and this will re-run the 1 test that failed. In the below scenario, it failed, but on the "retry" it passed. This shows the --last-failed command will queue up any tests that were in a failed state from the previous run.

Upcoming Article "Flakey Tests"

While it may not be a best practice to re-run failed tests, it is a great solution for those who are looking to get quick feedback. If you rely on this strategy and never take time to debug, or maintain your tests you will run into problems with your automation suite and the confidence you have in it. In the next article I'll share some of my thoughts around flakey tests and how I approach them!


Thanks for reading! If you found this helpful, reach out and let me know on LinkedIn or consider buying me a cup of coffee. If you want more content delivered to you in your inbox subscribe below, and be sure to leave a ❤️ to show some love.