Interface PlaywrightWorkerOptions

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

  • PlaywrightWorkerOptions

Properties

browserName: BrowserName

Name of the browser that runs tests. Defaults to 'chromium'. Most of the time you should set browserName in your TestConfig:

Usage

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

export default defineConfig({
use: {
browserName: 'firefox',
},
});
channel: string

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.

Usage

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

export default defineConfig({
projects: [
{
name: 'Microsoft Edge',
use: {
...devices['Desktop Edge'],
channel: 'msedge'
},
},
]
});
connectOptions: ConnectOptions

Usage

// playwright.config.ts
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.

defaultBrowserType: BrowserName
headless: boolean

Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to true unless the devtools option is true.

Usage

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

export default defineConfig({
use: {
headless: false
},
});
launchOptions: Omit<LaunchOptions, "tracesDir">

Options used to launch the browser, as passed to browserType.launch([options]). Specific options testOptions.headless and testOptions.channel take priority over this.

NOTE Use custom browser args at your own risk, as some of them may break Playwright functionality.

Usage

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

export default defineConfig({
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
launchOptions: {
args: ['--start-maximized']
}
}
}
]
});
screenshot: ScreenshotMode | {
    mode: ScreenshotMode;
} & Pick<PageScreenshotOptions, "fullPage" | "omitBackground">

Whether 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

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

export default defineConfig({
use: {
screenshot: 'only-on-failure',
},
});

Learn more about automatic screenshots.

trace: TraceMode | "retry-with-trace" | {
    attachments?: boolean;
    mode: TraceMode;
    screenshots?: boolean;
    snapshots?: boolean;
    sources?: boolean;
}

Whether 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

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

export default defineConfig({
use: {
trace: 'on-first-retry'
},
});

Learn more about recording trace.

Type declaration

  • Optional attachments?: boolean
  • mode: TraceMode
  • Optional screenshots?: boolean
  • Optional snapshots?: boolean
  • Optional sources?: boolean
video: VideoMode | "retry-with-video" | {
    mode: VideoMode;
    size?: ViewportSize;
}

Whether 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

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

export default defineConfig({
use: {
video: 'on-first-retry',
},
});

Learn more about recording video.

Type declaration

Generated using TypeDoc