How do I configure Playwright to stop testing and exit when a certain number of test failures is reached?


Sure, you can configure Playwright to exit the test run if all tests pass. This is done using the maxFailures configuration option.

Here's how you can use it:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  maxFailures: process.env.CI ? 1 : 0,

In this code snippet, maxFailures is set to 1 if the CI environment variable is defined, indicating a CI server run. Otherwise, it's set to 0.

This configuration ensures that if the number of test failures reaches or exceeds the maxFailures value, Playwright will stop executing further tests and exit with an error.

By default, maxFailures is set to 0, which means this behavior is disabled. So, if you want Playwright to exit when all tests pass without any failures, you need to set maxFailures in your configuration file.

For more insights on handling flaky tests in Playwright, check out this blog post.


Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.