Playwright Test provides options to configure the default `browser`, `context` and `page` fixtures. For example there are options for `headless`, `viewport` and `ignoreHTTPSErrors`. You can also record a video or a trace for the test or capture a screenshot at the end.
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
baseURL: 'http://localhost:3000',
browserName: 'firefox',
headless: true,
},
};
export default config;
```
## Emulation
Playwright can [emulate different environments](./emulation.md) like mobile device, locale or timezone.
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.
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;
```
You can specify options separately instead of using predefined devices. There are also more options such as locale, geolocation, and timezone which can be configured.
-`colorScheme` - Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`.
-`deviceScaleFactor` - Specify device scale factor (can be thought of as dpr). Defaults to `1`.
-`geolocation` - Context geolocation.
-`hasTouch` - Specifies if device supports touch events.
-`isMobile` - Whether the `meta viewport` tag is taken into account and touch events are enabled.
-`javaScriptEnabled` - Whether or not to enable JavaScript in the context.
-`locale` - User locale, for example `en-GB`, `de-DE`, etc.
-`permissions` - A list of permissions to grant to all pages in the context.
-`timezoneId` - Changes the timezone of the context.
-`userAgent` - Specific user agent to use in the context.
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
video: 'on-first-retry',
},
};
export default config;
```
## Record test trace
Playwright Test can produce test traces while running the tests. Later on, you can view the trace and get detailed information about Playwright execution by opening [Trace Viewer](./trace-viewer.md). By default tracing is off, controlled by the `trace` option.
-`'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.
-`'on-first-retry'` - Record trace only when retrying a test for the first time.
Trace files will appear in the test output directory, typically `test-results`.
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
trace: 'retain-on-failure',
},
};
export default config;
```
## More browser and context options
Any options accepted by [`method: BrowserType.launch`] or [`method: Browser.newContext`] can be put into `launchOptions` or `contextOptions` respectively in the `use` section.
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
launchOptions: {
slowMo: 50,
},
},
};
export default config;
```
However, most common ones like `headless` or `viewport` are available directly in the `use` section - see [basic options](#basic-options), [emulation](#emulation) or [network](#network).
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.
-`webServer: { command: string, port: number, timeout?: number, reuseExistingServer?: boolean, cwd?: string, env?: object }` - Launch a process and wait that it's ready before the tests will start. See [launch web server](./test-advanced.md#launching-a-development-web-server-during-the-tests) configuration for examples.
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.