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 }) => {
// ...
});
interface PlaywrightWorkerOptions {
    browserName: BrowserName;
    channel: string;
    connectOptions: ConnectOptions;
    defaultBrowserType: BrowserName;
    headless: boolean;
    launchOptions: Omit<LaunchOptions, "tracesDir">;
    screenshot: ScreenshotMode | {
        mode: ScreenshotMode;
    } & Pick<PageScreenshotOptions, "fullPage" | "omitBackground">;
    trace: TraceMode | "retry-with-trace" | {
        attachments?: boolean;
        mode: TraceMode;
        screenshots?: boolean;
        snapshots?: boolean;
        sources?: boolean;
    };
    video: VideoMode | "retry-with-video" | {
        mode: VideoMode;
        show?: {
            actions?: {
                duration?: number;
                fontSize?: number;
                position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
            };
            test?: {
                fontSize?: number;
                level?: "file" | "title" | "step";
                position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
            };
        };
        size?: ViewportSize;
    };
}

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.

Use "chromium" to opt in to new headless mode.

Use "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge", "msedge-beta", "msedge-dev", or "msedge-canary" to use branded 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.

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.
  • 'on-first-failure': Capture screenshot after each test's first 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.
  • 'on-first-retry': Record trace only when retrying a test for the first time.
  • 'on-all-retries': Record trace only when retrying a test.
  • 'retain-on-failure': Record trace for each test. When test run passes, remove the recorded trace.
  • 'retain-on-first-failure': Record trace for the first run of each test, but not for retries. When test run passes, remove the recorded trace.
  • 'retain-on-failure-and-retries': Record trace for each test run. Retains all traces when an attempt fails.

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;
    show?: {
        actions?: {
            duration?: number;
            fontSize?: number;
            position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
        };
        test?: {
            fontSize?: number;
            level?: "file" | "title" | "step";
            position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
        };
    };
    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.

To annotate actions in the video, pass show with action and/or test sub-options. The action option controls visual highlights on interacted elements with an optional delay in milliseconds (defaults to 500). The test option controls which test information is displayed as a status overlay.

Usage

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

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

Learn more about recording video.

Type declaration

  • mode: VideoMode
  • Optional show?: {
        actions?: {
            duration?: number;
            fontSize?: number;
            position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
        };
        test?: {
            fontSize?: number;
            level?: "file" | "title" | "step";
            position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
        };
    }
    • Optional actions?: {
          duration?: number;
          fontSize?: number;
          position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
      }
      • Optional duration?: number
      • Optional fontSize?: number
      • Optional position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right"
    • Optional test?: {
          fontSize?: number;
          level?: "file" | "title" | "step";
          position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right";
      }
      • Optional fontSize?: number
      • Optional level?: "file" | "title" | "step"
      • Optional position?: "top-left" | "top" | "top-right" | "bottom-left" | "bottom" | "bottom-right"
  • Optional size?: ViewportSize