Rayrun
← Back to Discord Forum

How to exit process after test(s) failure

If tests pass, the process exits successfully but if a test fails, I see a message like so: Serving HTML report at http://localhost:8000. Press Ctrl+C to quit. and the process is running until interrupted by using CTRL + C. Is there a configuration we can set to exit playwright similar to when the tests pass? Thanks

This thread is trying to answer question "Is there a configuration we can set to exit playwright similar to when the tests pass?"

2 replies
chaitanya_k

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

export default defineConfig({ reporter: [['html', { open: 'never' }]], });

Answer

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.

Related Discord Threads

TwitterGitHubLinkedIn
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 [email protected].