TestOptions
Playwright Test provides many options to configure test environment, Browser, BrowserContext and more.
These options are usually provided in the configuration file through testConfig.use and testProject.use.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
headless: false,
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
video: 'on-first-retry',
},
});
Alternatively, with test.use() you can override some options for a file.
import { test, expect } from '@playwright/test';
// Run tests in this file with portrait-like viewport.
test.use({ viewport: { width: 600, height: 900 } });
test('my portrait test', async ({ page }) => {
// ...
});
Properties
acceptDownloads
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
acceptDownloads: false,
},
});
Whether to automatically download all the attachments. Defaults to true
where all the downloads are accepted.
Type
actionTimeout
Added in: v1.10Default timeout for each Playwright action in milliseconds, defaults to 0 (no timeout).
This is a default timeout for all Playwright actions, same as configured via page.setDefaultTimeout().
Usage
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
},
});
Learn more about various timeouts.
Type
baseURL
Added in: v1.10Usage
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',
},
});
When using page.goto(), page.route(), page.waitForURL(), page.waitForRequest(), or page.waitForResponse() it takes the base URL in consideration by using the URL()
constructor for building the corresponding URL. Examples:
- baseURL:
http://localhost:3000
and navigating to/bar.html
results inhttp://localhost:3000/bar.html
- baseURL:
http://localhost:3000/foo/
and navigating to./bar.html
results inhttp://localhost:3000/foo/bar.html
- baseURL:
http://localhost:3000/foo
(without trailing slash) and navigating to./bar.html
results inhttp://localhost:3000/bar.html
Type
browserName
Added in: v1.10Name of the browser that runs tests. Defaults to 'chromium'
. Most of the time you should set browserName
in your TestConfig:
Usage
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
use: {
browserName: 'firefox',
},
});
Type
- "chromium"|"firefox"|"webkit"
bypassCSP
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
bypassCSP: true,
}
});
Toggles bypassing page's Content-Security-Policy.
Type
channel
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{
name: 'Microsoft Edge',
use: {
...devices['Desktop Edge'],
channel: 'msedge'
},
},
]
});
Browser distribution channel. Supported values are "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge", "msedge-beta", "msedge-dev", "msedge-canary". Read more about using Google Chrome and Microsoft Edge.
Type
colorScheme
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
colorScheme: 'dark',
},
});
Emulates 'prefers-colors-scheme'
media feature, supported values are 'light'
, 'dark'
, 'no-preference'
. See page.emulateMedia() for more details. Passing null
resets emulation to system defaults. Defaults to 'light'
.
Type
- null|"light"|"dark"|"no-preference"
connectOptions
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
connectOptions: {
wsEndpoint: 'ws://localhost:5678',
},
},
});
When connect options are specified, default fixtures.browser, fixtures.context and fixtures.page use the remote browser instead of launching a browser locally, and any launch options like testOptions.headless or testOptions.channel are ignored.
Type
- void|Object
wsEndpoint
stringA browser websocket endpoint to connect to.
headers
void|Object<string, string> (optional)Additional HTTP headers to be sent with web socket connect request. Optional.
timeout
number (optional)Timeout in milliseconds for the connection to be established. Optional, defaults to no timeout.
contextOptions
Added in: v1.10Options used to create the context, as passed to browser.newContext(). Specific options like testOptions.viewport take priority over this.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
contextOptions: {
reducedMotion: 'reduce',
},
},
});
Type
deviceScaleFactor
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
viewport: { width: 2560, height: 1440 },
deviceScaleFactor: 2,
},
});
Specify device scale factor (can be thought of as dpr). Defaults to 1
. Learn more about emulating devices with device scale factor.
Type
extraHTTPHeaders
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
extraHTTPHeaders: {
'X-My-Header': 'value',
},
},
});
An object containing additional HTTP headers to be sent with every request.
Type
geolocation
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
geolocation: { longitude: 12.492507, latitude: 41.889938 },
},
});
Learn more about geolocation.
Type
hasTouch
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
hasTouch: true
},
});
Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation.
Type
headless
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
headless: false
},
});
Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to true
unless the devtools
option is true
.
Type
httpCredentials
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
httpCredentials: {
username: 'user',
password: 'pass',
},
},
});
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
Type
ignoreHTTPSErrors
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
ignoreHTTPSErrors: true,
},
});
Whether to ignore HTTPS errors when sending network requests. Defaults to false
.
Type
isMobile
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
isMobile: false,
},
});
Whether the meta viewport
tag is taken into account and touch events are enabled. isMobile is a part of device, so you don't actually need to set it manually. Defaults to false
and is not supported in Firefox. Learn more about mobile emulation.
Type
javaScriptEnabled
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
javaScriptEnabled: false,
},
});
Whether or not to enable JavaScript in the context. Defaults to true
. Learn more about disabling JavaScript.
Type
launchOptions
Added in: v1.10Options used to launch the browser, as passed to browserType.launch(). Specific options testOptions.headless and testOptions.channel take priority over this.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
launchOptions: {
args: ['--start-maximized'],
},
}
]
});
Type
locale
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
locale: 'it-IT',
},
});
Specify user locale, for example en-GB
, de-DE
, etc. Locale will affect navigator.language
value, Accept-Language
request header value as well as number and date formatting rules. Learn more about emulation in our emulation guide.
Type
navigationTimeout
Added in: v1.10Timeout for each navigation action in milliseconds. Defaults to 0 (no timeout).
This is a default navigation timeout, same as configured via page.setDefaultNavigationTimeout().
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
navigationTimeout: 3000,
},
});
Learn more about various timeouts.
Type
offline
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
offline: true
},
});
Whether to emulate network being offline. Defaults to false
. Learn more about network emulation.
Type
permissions
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
permissions: ['notifications'],
},
});
A list of permissions to grant to all pages in this context. See browserContext.grantPermissions() for more details.
Type
proxy
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
proxy: {
server: 'http://myproxy.com:3128',
bypass: 'localhost',
},
},
});
Network proxy settings.
Type
- Object
server
stringProxy to be used for all requests. HTTP and SOCKS proxies are supported, for example
http://myproxy.com:3128
orsocks5://myproxy.com:3128
. Short formmyproxy.com:3128
is considered an HTTP proxy.bypass
string (optional)Optional comma-separated domains to bypass proxy, for example
".com, chromium.org, .domain.com"
.username
string (optional)Optional username to use if HTTP proxy requires authentication.
password
string (optional)Optional password to use if HTTP proxy requires authentication.
screenshot
Added in: v1.10Whether to automatically capture a screenshot after each test. Defaults to 'off'
.
'off'
: Do not capture screenshots.'on'
: Capture screenshot after each test.'only-on-failure'
: Capture screenshot after each test failure.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
},
});
Learn more about automatic screenshots.
Type
- Object|"off"|"on"|"only-on-failure"
mode
"off"|"on"|"only-on-failure"Automatic screenshot mode.
fullPage
boolean (optional)When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
false
.omitBackground
boolean (optional)Hides default white background and allows capturing screenshots with transparency. Not applicable to
jpeg
images. Defaults tofalse
.
serviceWorkers
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
serviceWorkers: 'allow'
},
});
Whether to allow sites to register Service workers. Defaults to 'allow'
.
'allow'
: Service Workers can be registered.'block'
: Playwright will block all registration of Service Workers.
Type
- "allow"|"block"
storageState
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
storageState: 'storage-state.json',
},
});
Learn more about storage state and auth.
Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via browserContext.storageState().
Type
- string|Object
name
stringvalue
stringdomain
stringDomain and path are required. For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com"
path
stringDomain and path are required
expires
numberUnix time in seconds.
httpOnly
booleansecure
booleansameSite
"Strict"|"Lax"|"None"sameSite flag
Cookies to set for context
localStorage to set for context
testIdAttribute
Added in: v1.27Custom attribute to be used in page.getByTestId(). data-testid
is used by default.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
testIdAttribute: 'pw-test-id',
},
});
timezoneId
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
timezoneId: 'Europe/Rome',
},
});
Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs.
Type
trace
Added in: v1.10Whether to record trace for each test. Defaults to 'off'
.
'off'
: Do not record trace.'on'
: Record trace for each test.'retain-on-failure'
: Record trace for each test, but remove all traces from successful test runs.'on-first-retry'
: Record trace only when retrying a test for the first time.'on-all-retries'
: Record traces only when retrying for all retries.
For more control, pass an object that specifies mode
and trace features to enable.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
trace: 'on-first-retry'
},
});
Learn more about recording trace.
Type
- Object|"off"|"on"|"retain-on-failure"|"on-first-retry"
mode
"off"|"on"|"retain-on-failure"|"on-first-retry"|"on-all-retries"Trace recording mode.
attachments
boolean (optional)Whether to include test attachments. Defaults to true. Optional.
screenshots
boolean (optional)Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview. Defaults to true. Optional.
snapshots
boolean (optional)Whether to capture DOM snapshot on every action. Defaults to true. Optional.
sources
boolean (optional)Whether to include source files for trace actions. Defaults to true. Optional.
userAgent
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
userAgent: 'some custom ua',
},
});
Specific user agent to use in this context.
Type
video
Added in: v1.10Whether to record video for each test. Defaults to 'off'
.
'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.'on-first-retry'
: Record video only when retrying a test for the first time.
To control video size, pass an object with mode
and size
properties. If video size is not specified, it will be equal to testOptions.viewport scaled down to fit into 800x800. If viewport
is not configured explicitly the video size defaults to 800x450. Actual picture of each page will be scaled down if necessary to fit the specified size.
Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
video: 'on-first-retry',
},
});
Learn more about recording video.
Type
- Object|"off"|"on"|"retain-on-failure"|"on-first-retry"
viewport
Added in: v1.10Usage
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
viewport: { width: 100, height: 100 },
},
});
Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use null
to disable the consistent viewport emulation. Learn more about viewport emulation.
The null
value opts out from the default presets, makes viewport depend on the host window size defined by the operating system. It makes the execution of the tests non-deterministic.
Type