Rayrun

What is the method to continue with the rest of the tests even if one fails in Playwright test runner?

Answer

Handling Test Failures in Playwright

In Playwright, you can handle test failures in two ways: fail fast or fail soft.

Fail Fast with test.fail()

The test.fail() function in Playwright marks a test as "should fail". When this test runs, Playwright ensures it fails. This is useful for acknowledging broken functionality until it's fixed. Here's how you use it:

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

test('not yet ready', async ({ page }) => {
  test.fail();
  // ... rest of your code
});

Fail Soft with Soft Assertions

If you want to continue running all tests even if some fail, use soft assertions. These don't immediately terminate the execution when failed. Instead, they compile and display a list of failed assertions once all tests have ended. Here's an example:

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

await expect.soft(page.getByTestId('status')).toHaveText('Success');
// ... continue executing more checks or actions

With soft assertions, even if one assertion fails, other checks or actions will still be executed. Any subsequent failures will be recorded and displayed at the end of the test execution.

So, depending on your needs, you can use test.fail() for a fail fast approach, or soft assertions with expect.soft() to continue executing all tests and fail soft.

References

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

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 luc@ray.run.