Interface PlaywrightTestOptions

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.

// playwright.config.ts
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(options) you can override some options for a file.

// example.spec.ts
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 }) => {
// ...
});

Hierarchy

  • PlaywrightTestOptions

Properties

acceptDownloads: boolean

Whether to automatically download all the attachments. Defaults to true where all the downloads are accepted.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
acceptDownloads: false,
},
});
actionTimeout: number

Default 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(timeout).

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.

baseURL: string

When using page.goto(url[, options]), page.route(url, handler[, options]), page.waitForURL(url[, options]), page.waitForRequest(urlOrPredicate[, options]), or page.waitForResponse(urlOrPredicate[, options]) it takes the base URL in consideration by using the URL() constructor for building the corresponding URL. Unset by default. Examples:

  • baseURL: http://localhost:3000 and navigating to /bar.html results in http://localhost:3000/bar.html
  • baseURL: http://localhost:3000/foo/ and navigating to ./bar.html results in http://localhost:3000/foo/bar.html
  • baseURL: http://localhost:3000/foo (without trailing slash) and navigating to ./bar.html results in http://localhost:3000/bar.html

Usage

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',
},
});
bypassCSP: boolean

Toggles bypassing page's Content-Security-Policy. Defaults to false.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
bypassCSP: true,
}
});
colorScheme: ColorScheme

Emulates 'prefers-colors-scheme' media feature, supported values are 'light', 'dark', 'no-preference'. See page.emulateMedia([options]) for more details. Passing null resets emulation to system defaults. Defaults to 'light'.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
colorScheme: 'dark',
},
});
contextOptions: BrowserContextOptions

Options used to create the context, as passed to browser.newContext([options]). Specific options like testOptions.viewport take priority over this.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
contextOptions: {
reducedMotion: 'reduce',
},
},
});
deviceScaleFactor: number

Specify device scale factor (can be thought of as dpr). Defaults to 1. Learn more about emulating devices with device scale factor.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
viewport: { width: 2560, height: 1440 },
deviceScaleFactor: 2,
},
});
extraHTTPHeaders: {
    [key: string]: string;
}

An object containing additional HTTP headers to be sent with every request. Defaults to none.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
extraHTTPHeaders: {
'X-My-Header': 'value',
},
},
});

Type declaration

  • [key: string]: string
geolocation: Geolocation

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
geolocation: { longitude: 12.492507, latitude: 41.889938 },
},
});

Learn more about geolocation.

hasTouch: boolean

Specifies if viewport supports touch events. Defaults to false. Learn more about mobile emulation.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
hasTouch: true
},
});
httpCredentials: HTTPCredentials

Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
httpCredentials: {
username: 'user',
password: 'pass',
},
},
});
ignoreHTTPSErrors: boolean

Whether to ignore HTTPS errors when sending network requests. Defaults to false.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
ignoreHTTPSErrors: true,
},
});
isMobile: boolean

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.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
isMobile: false,
},
});
javaScriptEnabled: boolean

Whether or not to enable JavaScript in the context. Defaults to true. Learn more about disabling JavaScript.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
javaScriptEnabled: false,
},
});
locale: string

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. Defaults to the system default locale. Learn more about emulation in our emulation guide.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
locale: 'it-IT',
},
});
navigationTimeout: number

Timeout for each navigation action in milliseconds. Defaults to 0 (no timeout).

This is a default navigation timeout, same as configured via page.setDefaultNavigationTimeout(timeout).

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
navigationTimeout: 3000,
},
});

Learn more about various timeouts.

offline: boolean

Whether to emulate network being offline. Defaults to false. Learn more about network emulation.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
offline: true
},
});
permissions: string[]

A list of permissions to grant to all pages in this context. See browserContext.grantPermissions(permissions[, options]) for more details. Defaults to none.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
permissions: ['notifications'],
},
});
proxy: {
    bypass?: string;
    password?: string;
    server: string;
    username?: string;
}

Network proxy settings.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
proxy: {
server: 'http://myproxy.com:3128',
bypass: 'localhost',
},
},
});

Type declaration

  • Optional bypass?: string

    Optional comma-separated domains to bypass proxy, for example ".com, chromium.org, .domain.com".

  • Optional password?: string

    Optional password to use if HTTP proxy requires authentication.

  • server: string

    Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example http://myproxy.com:3128 or socks5://myproxy.com:3128. Short form myproxy.com:3128 is considered an HTTP proxy.

  • Optional username?: string

    Optional username to use if HTTP proxy requires authentication.

serviceWorkers: ServiceWorkerPolicy

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.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
serviceWorkers: 'allow'
},
});
storageState: StorageState

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([options]).

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
storageState: 'storage-state.json',
},
});

Details

When storage state is set up in the config, it is possible to reset storage state for a file:

// not-signed-in.spec.ts
import { test } from '@playwright/test';

// Reset storage state for this file to avoid being authenticated
test.use({ storageState: { cookies: [], origins: [] } });

test('not signed in test', async ({ page }) => {
// ...
});
testIdAttribute: string

Custom attribute to be used in page.getByTestId(testId). data-testid is used by default.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
testIdAttribute: 'pw-test-id',
},
});
timezoneId: string

Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
timezoneId: 'Europe/Rome',
},
});
userAgent: string

Specific user agent to use in this context.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
userAgent: 'some custom ua',
},
});
viewport: ViewportSize

Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use null to disable the consistent viewport emulation. Learn more about viewport emulation.

NOTE 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.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
use: {
viewport: { width: 100, height: 100 },
},
});

Generated using TypeDoc