Playwright Tests supports browser and context options that you typically pass to [`method: BrowserType.launch`] and [`method: Browser.newContext`] methods, for example `headless`, `viewport` or `ignoreHTTPSErrors`. It also provides options to record video for the test or capture screenshot at the end.
- Browser options match [`method: BrowserType.launch`] method.
- Context options match [`method: Browser.newContext`] method.
-`screenshot` option - whether to capture a screenshot after each test, off by default. Screenshot will appear in the test output directory, typically `test-results`.
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](./test-advanced.md) 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, `'**/test-assets'`.
-`testMatch`: Glob patterns or regular expressions that match test files. For example, `'**/todo-tests/*.spec.ts'`. By default, Playwright Test runs `.*(test|spec)\.(js|ts|mjs)` files.
-`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.
```js
// playwright.config.js
module.exports = {
// Look for test files in the "tests" directory, relative to this configuration file
testDir: 'tests',
// Each test is given 30 seconds
timeout: 30000,
// Forbid test.only on CI
forbidOnly: !!process.env.CI,
// Two retries for each test
retries: 2,
// Limit the number of workers on CI, use default locally
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.
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](./test-advanced.md#projects) feature to run the same set of tests in multiple configurations.
```js
// playwright.config.js
const { devices } = require('playwright');
module.exports = {
projects: [
// "Pixel 4" tests use Chromium browser.
{
name: 'Pixel 4',
use: {
browserName: 'chromium',
...devices['Pixel 4'],
},
},
// "iPhone 11" tests use WebKit browser.
{
name: 'iPhone 11',
use: {
browserName: 'webkit',
...devices['iPhone 11'],
},
},
],
};
```
```ts
// playwright.config.ts
import { PlaywrightTestConfig } from 'playwright/test';
import { devices } from 'playwright';
const config: PlaywrightTestConfig = {
projects: [
// "Pixel 4" tests use Chromium browser.
{
name: 'Pixel 4',
use: {
browserName: 'chromium',
...devices['Pixel 4'],
},
},
// "iPhone 11" tests use WebKit browser.
{
name: 'iPhone 11',
use: {
browserName: 'webkit',
...devices['iPhone 11'],
},
},
],
};
export default config;
```
## Network mocking
You don't have to configure anything to mock network requests. Just define a custom [Route] that mocks network for a browser context.