Playwright

June 11, 2024

What is Playwright?

Playwright is an end to end testing framework for web apps. It can run tests inside of multiple headless browsers at once.

Enabling XML Output

Playwright has multiple built in reporters. To get XML output use the junit reporter.

1npx playwright test --reporter=junit

The output file can be set by either using the PLAYWRIGHT_JUNIT_OUTPUT_NAME environment variable or the outputFile attribute in the playwright.config.ts file.

1PLAYWRIGHT_JUNIT_OUTPUT_FILE=tests/results.xml npx playwright test --reporter=junit

or

1import { defineConfig } from '@playwright/test';
2
3export default defineConfig({
4 reporter: [['junit', { outputFile: 'tests/results.xml' }]],
5});

See the Playwright JUnit reporter docs for more information.

Test Suite naming

Playwright tests are driven by functions in *.spec.ts files. The XML testsuite name attributes will automatically be set by the description parameters to the test functions. The name attribute of the <testsuites> element can be set with the PLAYWRIGHT_JUNIT_SUITE_NAME environment variable.

Playwright does not support including the full filepath of the failed test in the XML output.

Handling Retries

To retry failed tests, use the --retries option:

1npx playwright test --retries=3

If you need to retry a lot of tests that is a strong indicator that you may have flaky tests. These are tests that sometimes pass and sometimes fail, slowing down your development process. You can get early access to Trunk’s new Flaky Tests tool to manage these types of tests better.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users