Interface FullConfig<TestArgs, WorkerArgs>

Playwright Test provides many options to configure how your tests are collected and executed, for example timeout or testDir. These options are described in the TestConfig object in the configuration file.

Playwright Test supports running multiple test projects at the same time. Project-specific options should be put to testConfig.projects, but top-level TestConfig can also define base options shared between all projects.

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

export default defineConfig({
timeout: 30000,
globalTimeout: 600000,
reporter: 'list',
testDir: './tests',
});

Type Parameters

  • TestArgs = {}

  • WorkerArgs = {}

Hierarchy

  • FullConfig

Properties

configFile?: string
forbidOnly: boolean

Whether to exit with an error if any tests or groups are marked as test.only(title[, details, body]) or test.describe.only([title, details, callback]). Useful on CI.

Usage

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

export default defineConfig({
forbidOnly: !!process.env.CI,
});
fullyParallel: boolean

Playwright Test runs tests in parallel. In order to achieve that, it runs several worker processes that run at the same time. By default, test files are run in parallel. Tests in a single file are run in order, in the same worker process.

You can configure entire test run to concurrently execute all tests in all files using this option.

Usage

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

export default defineConfig({
fullyParallel: true,
});
globalSetup: string

Path to the global setup file. This file will be required and run before all the tests. It must export a single function that takes a [TestConfig] argument.

Learn more about global setup and teardown.

Usage

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

export default defineConfig({
globalSetup: './global-setup',
});
globalTeardown: string

Path to the global teardown file. This file will be required and run after all the tests. It must export a single function. See also testConfig.globalSetup.

Learn more about global setup and teardown.

Usage

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

export default defineConfig({
globalTeardown: './global-teardown',
});
globalTimeout: number

Maximum time in milliseconds the whole test suite can run. Zero timeout (default) disables this behavior. Useful on CI to prevent broken setup from running too long and wasting resources. Learn more about various timeouts.

Usage

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

export default defineConfig({
globalTimeout: process.env.CI ? 60 * 60 * 1000 : undefined,
});
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 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.

Usage

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

export default defineConfig({
grep: /smoke/,
});
grepInvert: RegExp | RegExp[]

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

grepInvert option is also useful for tagging tests.

Usage

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

export default defineConfig({
grepInvert: /manual/,
});
maxFailures: number

The maximum number of test failures for the whole test suite run. After reaching this number, testing will stop and exit with an error. Setting to zero (default) disables this behavior.

Also available in the command line with the --max-failures and -x options.

Usage

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

export default defineConfig({
maxFailures: process.env.CI ? 1 : 0,
});
metadata: Metadata

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

Usage

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

export default defineConfig({
metadata: 'acceptance tests',
});
preserveOutput: "always" | "never" | "failures-only"

Whether to preserve test output in the testConfig.outputDir. Defaults to 'always'.

  • 'always' - preserve output for all tests;
  • 'never' - do not preserve output for any tests;
  • 'failures-only' - only preserve output for failed tests.

Usage

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

export default defineConfig({
preserveOutput: 'always',
});
projects: FullProject<TestArgs, WorkerArgs>[]

Playwright Test supports running multiple test projects at the same time. See TestProject for more information.

Usage

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

export default defineConfig({
projects: [
{ name: 'chromium', use: devices['Desktop Chrome'] }
]
});
quiet: boolean

Whether to suppress stdio and stderr output from the tests.

Usage

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

export default defineConfig({
quiet: !!process.env.CI,
});
reportSlowTests: {
    max: number;
    threshold: number;
}

Whether to report slow test files. Pass null to disable this feature.

Usage

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

export default defineConfig({
reportSlowTests: null,
});

Details

Test files that took more than threshold milliseconds are considered slow, and the slowest ones are reported, no more than max number of them. Passing zero as max reports all test files that exceed the threshold.

Type declaration

  • max: number
  • threshold: number

The list of reporters to use. Each reporter can be:

  • A builtin reporter name like 'list' or 'json'.
  • A module name like 'my-awesome-reporter'.
  • A relative path to the reporter like './reporters/my-awesome-reporter.js'.

You can pass options to the reporter in a tuple like ['json', { outputFile: './report.json' }].

Learn more in the reporters guide.

Usage

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

export default defineConfig({
reporter: 'line',
});
rootDir: string
shard: {
    current: number;
    total: number;
}

Shard tests and execute only the selected shard. Specify in the one-based form like { total: 5, current: 2 }.

Learn more about parallelism and sharding with Playwright Test.

Usage

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

export default defineConfig({
shard: { total: 10, current: 3 },
});

Type declaration

  • current: number
  • total: number
updateSnapshots: "none" | "all" | "missing"

Whether to update expected snapshots with the actual results produced by the test run. Defaults to 'missing'.

  • 'all' - All tests that are executed will update snapshots that did not match. Matching snapshots will not be updated.
  • 'none' - No snapshots are updated.
  • 'missing' - Missing snapshots are created, for example when authoring a new test and running it for the first time. This is the default.

Learn more about snapshots.

Usage

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

export default defineConfig({
updateSnapshots: 'missing',
});
version: string
webServer: TestConfigWebServer

Launch a development web server (or multiple) during the tests.

Details

If the port is specified, Playwright Test will wait for it to be available on 127.0.0.1 or ::1, before running the tests. If the url is specified, Playwright Test will wait for the URL to return a 2xx, 3xx, 400, 401, 402, or 403 status code before running the tests.

For continuous integration, you may want to use the reuseExistingServer: !process.env.CI option which does not use an existing server on the CI. To see the stdout, you can set the DEBUG=pw:webserver environment variable.

The port (but not the url) gets passed over to Playwright as a testOptions.baseURL. For example port 8080 produces baseURL equal http://localhost:8080. If webServer is specified as an array, you must explicitly configure the baseURL (even if it only has one entry).

NOTE It is also recommended to specify testOptions.baseURL in the config, so that tests could use relative urls.

Usage

// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
webServer: {
command: 'npm run start',
url: 'http://127.0.0.1:3000',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
use: {
baseURL: 'http://localhost:3000/',
},
});

Now you can use a relative path when navigating the page:

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

test('test', async ({ page }) => {
// This will result in http://localhost:3000/foo
await page.goto('/foo');
});

Multiple web servers (or background processes) can be launched:

// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
webServer: [
{
command: 'npm run start',
url: 'http://127.0.0.1:3000',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
{
command: 'npm run backend',
url: 'http://127.0.0.1:3333',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
}
],
use: {
baseURL: 'http://127.0.0.1:3000',
},
});
workers: number

The maximum number of concurrent worker processes to use for parallelizing tests. Can also be set as percentage of logical CPU cores, e.g. '50%'.

Playwright Test uses worker processes to run tests. There is always at least one worker process, but more can be used to speed up test execution.

Defaults to half of the number of logical CPU cores. Learn more about parallelism and sharding with Playwright Test.

Usage

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

export default defineConfig({
workers: 3,
});

Generated using TypeDoc