- Configure browser, context, videos and screenshots
- Testing options
- Different options for each browser
- Mobile emulation
- Network mocking
Playwright Tests supports browser and context options that you typically pass to browserType.launch([options]) and browser.newContext([options]) methods, for example
ignoreHTTPSErrors. It also provides options to record video for the test or capture screenshot at the end.
You can specify any options either locally in a test file, or globally in the configuration file.
- Browser options match browserType.launch([options]) method.
- Context options match browser.newContext([options]) method.
screenshotoption - whether to capture a screenshot after each test, off by default. Screenshot will appear in the test output directory, typically
'off'- Do not capture screenshots.
'on'- Capture screenshot after each test.
'only-on-failure'- Capture screenshot after each test failure.
traceoption - whether to record trace for each test, off by default. Trace will appear in the test output directory, typically
'off'- Do not record trace.
'on'- Record trace for each test.
'retain-on-failure'- Record trace for each test, but remove it from successful test runs.
'retry-with-trace'- Record trace only when retrying a test.
videooption - whether to record video for each test, off by default. Video will appear in the test output directory, typically
'off'- Do not record video.
'on'- Record video for each test.
'retain-on-failure'- Record video for each test, but remove all videos from successful test runs.
'retry-with-video'- Record video only when retrying a test.
playwright.config.ts) and specify options in the
Now run tests as usual, Playwright Test will pick up the configuration file automatically.
If you put your configuration file in a different place, pass it with
test.use() you can override some options for a file or a
The same works inside describe.
In addition to configuring Browser or BrowserContext, videos or screenshots, Playwright Test has many options to configure how your tests are run. Below are the most common ones, see advanced configuration for the full list.
forbidOnly: Whether to exit with an error if any tests are marked as
test.only. Useful on CI.
globalSetup: Path to the global setup file. This file will be required and run before all the tests. It must export a single function.
globalTeardown: Path to the global teardown file. This file will be required and run after all the tests. It must export a single function.
retries: The maximum number of retry attempts per test.
testDir: Directory with the test files.
testIgnore: Glob patterns or regular expressions that should be ignored when looking for the test files. For example,
testMatch: Glob patterns or regular expressions that match test files. For example,
'**/todo-tests/*.spec.ts'. By default, Playwright Test runs
timeout: Time in milliseconds given to each test.
workers: The maximum number of concurrent worker processes to use for parallelizing tests.
You can specify these options in the configuration file.
To specify different options per browser, for example command line arguments for Chromium, create multiple projects in your configuration file. Below is an example that runs all tests in three browsers, with different options.
Playwright Test will run all projects by default.
--project command line option to run a single project.
There are many more things you can do with projects:
- Run a subset of test by specifying different
testDirfor each project.
- Run tests in multiple configurations, for example with desktop Chromium and emulating Chrome for Android.
- Run "core" tests without retries to ensure stability of the core functionality, and use
retriesfor other tests.
- And much more! See advanced configuration for more details.
--browser command line option is not compatible with projects. Specify
browserName in each project instead.
You can use configuration file to make default
context emulate a mobile device.
Here is an example configuration that runs tests in "Pixel 4" and "iPhone 11" emulation modes. Note that it uses the projects feature to run the same set of tests in multiple configurations.
You don't have to configure anything to mock network requests. Just define a custom Route that mocks network for a browser context.
Alternatively, you can use page.route(url, handler) to mock network in a single test.