To continue running your test suite on failure in @playwright/test, you can use soft assertions and test retries.
Soft assertions allow you to make checks that won't stop the test when failed. Use expect.soft()
instead of expect()
:
await expect.soft(page.getByTestId('status')).toHaveText('Success');
This code checks if an element with a specific ID has text content equal to "Success". If it fails, the test execution continues, and the failure is added to a list of failed soft assertions.
Test retries enable failing tests to be retried multiple times until they pass or the maximum number of retries is reached. To enable retries for all tests, use the following command:
npx playwright test --retries=<number_of_retries>
Or, configure retries in your configuration file:
import { defineConfig } from '@playwright/test';
export default defineConfig({
// Give failing tests 3 retry attempts
retries: 3,
});
With this setup, any failing tests will be retried up to three times before being marked as failed.
By using soft assertions and test retries together, you can ensure that your entire test suite runs even if some individual tests fail initially.
If you still have questions, please ask a question and I will try to answer it.
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].