To take screenshots during test failures using soft assertions and attach them to the HTML report, follow these steps:
Install the VS Code extension for Playwright. Run tests in debug mode by right-clicking on the line next to your desired test. This opens a browser window and pauses at your breakpoint.
Soft assertions don't immediately terminate the test execution but compile and display a list of failed assertions once the test ends.
Use custom error messages as the second argument for the
await expect(page.getByText('Name'), 'should be logged in').toBeVisible();
The error would look like this:
Error: should be logged in Call log: • expect.toBeVisible with timeout 5000ms • waiting for "getByText('Name')".
To attach screenshots taken during failures to HTML reports, you need additional configuration. You can use custom expect messages to specify custom error messages for the
With these configurations, you can take screenshots at the exact moment of failure using soft assertions in the @playwright/test framework and attach them to the HTML report at the test step level.
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@example.com.