Interface FullProject<TestArgs, WorkerArgs>

Playwright Test supports running multiple test projects at the same time. This is useful for running tests in multiple configurations. For example, consider running tests against multiple browsers.

TestProject encapsulates configuration specific to a single project. Projects are configured in testConfig.projects specified in the configuration file. Note that all properties of TestProject are available in the top-level TestConfig, in which case they are shared between all projects.

Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile versions.

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

export default defineConfig({
// Options shared for all projects.
timeout: 30000,
use: {
ignoreHTTPSErrors: true,
},

// Options specific to each project.
projects: [
{
name: 'chromium',
use: devices['Desktop Chrome'],
},
{
name: 'firefox',
use: devices['Desktop Firefox'],
},
{
name: 'webkit',
use: devices['Desktop Safari'],
},
{
name: 'Mobile Chrome',
use: devices['Pixel 5'],
},
{
name: 'Mobile Safari',
use: devices['iPhone 12'],
},
],
});

Type Parameters

  • TestArgs = {}

  • WorkerArgs = {}

Hierarchy

  • FullProject

Properties

dependencies: string[]

List of projects that need to run before any test in this project runs. Dependencies can be useful for configuring the global setup actions in a way that every action is in a form of a test. Passing --no-deps argument ignores the dependencies and behaves as if they were not specified.

Using dependencies allows global setup to produce traces and other artifacts, see the setup steps in the test report, etc.

Usage

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

export default defineConfig({
projects: [
{
name: 'setup',
testMatch: /global.setup\.ts/,
},
{
name: 'chromium',
use: devices['Desktop Chrome'],
dependencies: ['setup'],
},
{
name: 'firefox',
use: devices['Desktop Firefox'],
dependencies: ['setup'],
},
{
name: 'webkit',
use: devices['Desktop Safari'],
dependencies: ['setup'],
},
],
});
grep: RegExp | RegExp[]

Filter to only run tests with a title matching one of the patterns. For example, passing grep: /cart/ should only run tests with "cart" in the title. Also available globally and in the command line with the -g option. The regular expression will be tested against the string that consists of the test file name, test.describe name (if any) and the test name divided by spaces, e.g. my-test.spec.ts my-suite my-test.

grep option is also useful for tagging tests.

grepInvert: RegExp | RegExp[]

Filter to only run tests with a title not matching one of the patterns. This is the opposite of testProject.grep. Also available globally and in the command line with the --grep-invert option.

grepInvert option is also useful for tagging tests.

metadata: Metadata

Metadata that will be put directly to the test report serialized as JSON.

name: string

Project name is visible in the report and during test execution.

outputDir: string

The output directory for files created during test execution. Defaults to <package.json-directory>/test-results.

This directory is cleaned at the start. When running a test, a unique subdirectory inside the testProject.outputDir is created, guaranteeing that test running in parallel do not conflict. This directory can be accessed by testInfo.outputDir and testInfo.outputPath(...pathSegments).

Here is an example that uses testInfo.outputPath(...pathSegments) to create a temporary file.

import { test, expect } from '@playwright/test';
import fs from 'fs';

test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('temporary-file.txt');
await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');
});

Use testConfig.outputDir to change this option for all projects.

repeatEach: number

The number of times to repeat each test, useful for debugging flaky tests.

Use testConfig.repeatEach to change this option for all projects.

retries: number

The maximum number of retry attempts given to failed tests. Learn more about test retries.

Use test.describe.configure([options]) to change the number of retries for a specific file or a group of tests.

Use testConfig.retries to change this option for all projects.

snapshotDir: string

The base directory, relative to the config file, for snapshot files created with toMatchSnapshot. Defaults to testProject.testDir.

The directory for each test can be accessed by testInfo.snapshotDir and testInfo.snapshotPath(...pathSegments).

This path will serve as the base directory for each test file snapshot directory. Setting snapshotDir to 'snapshots', the testInfo.snapshotDir would resolve to snapshots/a.spec.js-snapshots.

teardown?: string

Name of a project that needs to run after this and all dependent projects have finished. Teardown is useful to cleanup any resources acquired by this project.

Passing --no-deps argument ignores testProject.teardown and behaves as if it was not specified.

Usage

A common pattern is a "setup" dependency that has a corresponding "teardown":

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

export default defineConfig({
projects: [
{
name: 'setup',
testMatch: /global.setup\.ts/,
teardown: 'teardown',
},
{
name: 'teardown',
testMatch: /global.teardown\.ts/,
},
{
name: 'chromium',
use: devices['Desktop Chrome'],
dependencies: ['setup'],
},
{
name: 'firefox',
use: devices['Desktop Firefox'],
dependencies: ['setup'],
},
{
name: 'webkit',
use: devices['Desktop Safari'],
dependencies: ['setup'],
},
],
});
testDir: string

Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.

Each project can use a different directory. Here is an example that runs smoke tests in three browsers and all other tests in stable Chrome browser.

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

export default defineConfig({
projects: [
{
name: 'Smoke Chromium',
testDir: './smoke-tests',
use: {
browserName: 'chromium',
}
},
{
name: 'Smoke WebKit',
testDir: './smoke-tests',
use: {
browserName: 'webkit',
}
},
{
name: 'Smoke Firefox',
testDir: './smoke-tests',
use: {
browserName: 'firefox',
}
},
{
name: 'Chrome Stable',
testDir: './',
use: {
browserName: 'chromium',
channel: 'chrome',
}
},
],
});

Use testConfig.testDir to change this option for all projects.

testIgnore: string | RegExp | (string | RegExp)[]

Files matching one of these patterns are not executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.

For example, '**/test-assets/**' will ignore any files in the test-assets directory.

Use testConfig.testIgnore to change this option for all projects.

testMatch: string | RegExp | (string | RegExp)[]

Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.

By default, Playwright looks for files matching the following glob pattern: **/*.@(spec|test).?(c|m)[jt]s?(x). This means JavaScript or TypeScript files with ".test" or ".spec" suffix, for example login-screen.wrong-credentials.spec.ts.

Use testConfig.testMatch to change this option for all projects.

timeout: number

Timeout for each test in milliseconds. Defaults to 30 seconds.

This is a base timeout for all tests. Each test can configure its own timeout with test.setTimeout(timeout). Each file or a group of tests can configure the timeout with test.describe.configure([options]).

Use testConfig.timeout to change this option for all projects.

use: UseOptions<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>

Options for all tests in this project, for example testOptions.browserName. Learn more about configuration and see [available options]TestOptions.

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

export default defineConfig({
projects: [
{
name: 'Chromium',
use: {
browserName: 'chromium',
},
},
],
});

Use testConfig.use to change this option for all projects.

Generated using TypeDoc