Skip to main content
Version: 1.15

TestProject

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.tsimport { PlaywrightTestConfig, devices } from '@playwright/test';
const config: PlaywrightTestConfig = {  // Options shared for all projects.  timeout: 30000,  use: {    ignoreHTTPSErrors: true,  },
  // Options specific to each project.  projects: [    {      name: 'Desktop Chromium',      use: {        browserName: 'chromium',        viewport: { width: 1280, height: 720 },      },    },    {      name: 'Desktop Safari',      use: {        browserName: 'webkit',        viewport: { width: 1280, height: 720 },      }    },    {      name: 'Desktop Firefox',      use: {        browserName: 'firefox',        viewport: { width: 1280, height: 720 },      }    },    {      name: 'Mobile Chrome',      use: devices['Pixel 5'],    },    {      name: 'Mobile Safari',      use: devices['iPhone 12'],    },  ],};export default config;

testProject.expect#

  • type: <Object>
    • timeout <number> Default timeout for async expect matchers in milliseconds, defaults to 5000ms.
    • toMatchSnapshot <Object>
      • threshold <number> Image matching threshold between zero (strict) and one (lax).

Configuration for the expect assertion library.

testProject.metadata#

Any JSON-serializable metadata that will be put directly to the test report.

testProject.name#

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

testProject.outputDir#

The output directory for files created during test execution. Defaults to 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');});

testProject.repeatEach#

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

testProject.retries#

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

testProject.testDir#

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.tsimport { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {  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',      }    },  ],};export default config;

testProject.testIgnore#

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.

testProject.testMatch#

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 Test looks for files matching .*(test|spec)\.(js|ts|mjs).

testProject.timeout#

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

This is a base timeout for all tests. In addition, each test can configure its own timeout with test.setTimeout(timeout).

testProject.use#

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

// playwright.config.tsimport { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {  projects: [    {      name: 'Chromium',      use: {        browserName: 'chromium',      },    },  ],};export default config;