Skip to main content

Test API

The test object is the main entry point for defining tests in Playwright. It provides methods for creating test cases, organizing them into suites, and controlling test execution.

Importing

test()

Defines a test case.

Signature

string
required
Test title that will be shown in the test report.
TestDetails
Optional test details object:
Function
required
Async function containing the test code. Receives fixture arguments and testInfo.

Example

test.describe()

Groups tests into a suite. Test suites can be nested.

Signature

string
Suite title. Optional for anonymous suites.
TestDetails
Optional suite details (tags, annotations).
Function
required
Function that contains test definitions and other suite configuration.

Example

test.describe.configure()

Configure suite execution mode, timeout, and retries.
Example:

test.describe.only()

Run only this suite and skip all other tests.

test.describe.skip()

Skip all tests in this suite.

test.describe.fixme()

Mark all tests in this suite as “fixme” (known to be broken).

test.describe.parallel()

Run tests in this suite in parallel.

test.describe.serial()

Run tests in this suite serially (one after another).

Hooks

Hooks allow you to run setup and teardown code before and after tests.

test.beforeEach()

Runs before each test in the suite.

test.afterEach()

Runs after each test in the suite.

test.beforeAll()

Runs once before all tests in the suite.

test.afterAll()

Runs once after all tests in the suite.

Test Modifiers

test.only()

Run only this test and skip all others.

test.skip()

Skip a test or conditionally skip.

test.fixme()

Mark a test as “fixme” (known to be broken).

test.fail()

Mark a test as expected to fail. The test will pass if it fails and fail if it passes.

test.slow()

Mark a test as slow, tripling its timeout.

Advanced Features

test.step()

Create a custom test step for better reporting.
Example:

test.use()

Override fixture values for all tests in a file.
Example:

test.extend()

Extend test with custom fixtures.
Example:

test.info()

Get information about the currently running test.
Example:

test.setTimeout()

Set timeout for a test or suite.
Example:

TypeScript Definitions

See Also