Playwright Test and Reporter API
This appendix lists the configuration, Fixture, Reporter, and other APIs of the Playwright Test Runner.
Test Functions
| Method | Description |
test(name, fn) | Define a test |
test.describe(name, fn) | Define a test group |
test.describe.serial(name, fn) | Serial test group |
test.describe.parallel(name, fn) | Parallel test group |
test.describe.configure(options) | Configure group behavior (mode, retries) |
test.skip(name?, fn?) | Skip test |
test.fail(name?, fn?) | Mark as expected failure |
test.fixme(name?, fn?) | Mark as fixme (to be fixed) |
test.slow(name?, fn?) | Mark as slow test (timeout × 3) |
test.only(name, fn) | Run only this test |
test.beforeEach(fn) | Run before each test |
test.afterEach(fn) | Run after each test |
test.beforeAll(fn) | Run once before all tests |
test.afterAll(fn) | Run once after all tests |
test.extend(fixtures) | Create custom Fixture |
test.use(options) | Override configuration for the current scope |
test.setTimeout(ms) | Set timeout for the current test |
test.step(name, fn) | Define test steps (visible in report) |
test.info() | Get TestInfo object |
TestConfig Interface
| Field | Type | Description |
testDir | string | Test directory |
fullyParallel | boolean | Fully parallel |
workers | number | Number of workers |
retries | number | Number of retries |
timeout | number | Total test timeout |
reporter | string | array | Reporter |
forbidOnly | boolean | Forbidonly |
testMatch | string | RegExp | Test match pattern |
testIgnore | string | RegExp | Ignore pattern |
projects | Project[] | Project list |
webServer | object | Web server configuration |
globalSetup | string | Global setup script path |
globalTeardown | string | Global teardown script path |
use | object | Shared configuration |
expect | object | Assertion configuration |
TestInfo Interface
| Field/Method | Description |
testInfo.title | Test name |
testInfo.file | Test file path |
testInfo.line | Line number of the test |
testInfo.column | Column number of the test |
testInfo.expectedStatus | Expected status:'passed' | 'failed' | 'skipped' |
testInfo.timeout | Current test timeout |
testInfo.annotations | Annotation list |
testInfo.attachments | Attachment list |
testInfo.project.name | Current project name |
testInfo.retry | Current retry count |
testInfo.parallelIndex | Parallel index |
testInfo.skip(reason?) | Skip test (dynamic) |
testInfo.fail(reason?) | Mark as failed (dynamic) |
testInfo.attach(name, options?) | Attach file to report |
Fixtures Interface
| Fixture | Type | Description |
page | Page | Browser page |
context | BrowserContext | Browser context |
browser | Browser | Browser instance |
browserName | string | Browser name |
request | APIRequestContext | HTTP request client |
WorkerInfo Interface
| Field | Description |
workerInfo.project.name | Project name |
workerInfo.parallelIndex | Worker parallel index |
workerInfo.config | FullConfig object |
Reporter Interface
| Method | Description |
reporter.onBegin(config, suite) | Test run start |
reporter.onTestBegin(test) | Single test start |
reporter.onTestEnd(test, result) | Single test end |
reporter.onStepBegin(test, result, step) | Step start |
reporter.onStepEnd(test, result, step) | Step end |
reporter.onEnd(result) | Test run end |
reporter.onExit() | Process exit |
reporter.printsToStdio() | Whether to output to stdout |
Suite Class
| Field | Description |
suite.title | Suite name |
suite.suites | Child suite list |
suite.tests | Test list |
suite.location | Suite location |
TestCase Class
| Field | Description |
test.title | Test name |
test.location | Test location |
test.expectedStatus | Expected status |
test.annotations | Annotation list |
test.parent | Parent Suite |
test.id() | Test ID |
TestResult Class
| Field | Description |
result.status | Status:'passed' | 'failed' | 'skipped' | 'interrupted' |
result.duration | Duration (milliseconds) |
result.error | Error information (TestError) |
result.attachments | Attachment list |
result.stdout | Standard output |
result.stderr | Standard error |
Electron API
| Method | Description |
electron.launch(options?) | Launch Electron application |
ElectronApplication Class
| Method | Description |
electronApp.firstWindow() | Get the first window |
electronApp.windows() | Get all windows |
electronApp.close() | Close application |
Android API
| Method/Class | Description |
android.devices() | Get list of connected devices |
AndroidDevice | Android device object |
AndroidWebView | WebView object |
Other extensions