Playwright Test and Reporter API
This appendix lists APIs such as configuration, Fixtures, and Reporter 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 a test |
test.fail(name?, fn?) |
Mark as expected failure |
test.fixme(name?, fn?) |
Mark as to be fixed |
test.slow(name?, fn?) |
Mark as slow test (timeout x3) |
test.only(name, fn) |
Run only this test |
test.beforeEach(fn) |
Execute before each test |
test.afterEach(fn) |
Execute after each test |
test.beforeAll(fn) |
Execute once before all tests |
test.afterAll(fn) |
Execute once after all tests |
test.extend(fixtures) |
Create a custom Fixture |
test.use(options) |
Override the configuration for the current scope |
test.setTimeout(ms) |
Set the current test's timeout |
test.step(name, fn) |
Define a test step (visible in the report) |
test.info() |
Get the TestInfo object |
TestConfig configuration 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 | Forbid only |
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
| Fields/Methods | Description |
|---|---|
testInfo.title |
Test name |
testInfo.file |
Test file path |
testInfo.line |
Test line number |
testInfo.column |
Test column number |
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 a file to the report |
Fixtures interface
| Fixture | Type | Description |
|---|---|---|
page |
Page | Browser tab |
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 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 end |
reporter.onExit() |
Process exit |
reporter.printsToStdio() |
Whether to output to standard output |
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 |
Execution duration (milliseconds) |
result.error |
Error message (TestError) |
result.attachments |
Attachment list |
result.stdout |
Standard output |
result.stderr |
Standard error |
Electron API
| Method | Description |
|---|---|
electron.launch(options?) |
Launch an Electron application |
ElectronApplication class
| Method | Description |
|---|---|
electronApp.firstWindow() |
Get the first window |
electronApp.windows() |
Get all windows |
electronApp.close() |
Close the application |
Android API
| Method/class | Description |
|---|---|
android.devices() |
Get the list of connected devices |
AndroidDevice |
Android device object |
AndroidWebView |
WebView object |