File: class-testinfo.md | Updated: 11/18/2025
On this page
TestInfo contains information about currently running test. It is available to test functions, test.beforeEach()
, test.afterEach()
, test.beforeAll()
and test.afterAll()
hooks, and test-scoped fixtures. TestInfo provides utilities to control test execution: attach files, update test timeout, determine which test is currently running and whether it was retried, etc.
import { test, expect } from '@playwright/test';test('basic test', async ({ page }, testInfo) => { expect(testInfo.title).toBe('basic test'); await page.screenshot(testInfo.outputPath('screenshot.png'));});
Methods
Added in: v1.10 testInfo.attach
Attach a value or a file from disk to the current test. Some reporters show test attachments. Either path or body must be specified, but not both.
For example, you can attach a screenshot to the test:
import { test, expect } from '@playwright/test';test('basic test', async ({ page }, testInfo) => { await page.goto('https://playwright.dev'); const screenshot = await page.screenshot(); await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });});
Or you can attach files returned by your APIs:
import { test, expect } from '@playwright/test';import { download } from './my-custom-helpers';test('basic test', async ({}, testInfo) => { const tmpPath = await download('a'); await testInfo.attach('downloaded', { path: tmpPath });});
note
testInfo.attach() automatically takes care of copying attached files to a location that is accessible to reporters. You can safely remove the attachment after awaiting the attach call.
Usage
await testInfo.attach(name);await testInfo.attach(name, options);
Arguments
Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk.
options Object
(optional)
body string
| Buffer
(optional)#
Attachment body. Mutually exclusive with path .
contentType string
(optional)#
Content type of this attachment to properly present in the report, for example 'application/json' or 'image/png'. If omitted, content type is inferred based on the path
, or defaults to text/plain for string
attachments and application/octet-stream for Buffer
attachments.
Path on the filesystem to the attached file. Mutually exclusive with body .
Returns
Added in: v1.10 testInfo.fail()
Marks the currently running test as "should fail". Playwright Test runs this test and ensures that it is actually failing. This is useful for documentation purposes to acknowledge that some functionality is broken until it is fixed. This is similar to test.fail() .
Usage
testInfo.fail();
Added in: v1.10 testInfo.fail(condition)
Conditionally mark the currently running test as "should fail" with an optional description. This is similar to test.fail() .
Usage
testInfo.fail(condition);testInfo.fail(condition, description);
Arguments
Test is marked as "should fail" when the condition is true.
description string
(optional)#
Optional description that will be reflected in a test report.
Added in: v1.10 testInfo.fixme()
Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to test.fixme() .
Usage
testInfo.fixme();
Added in: v1.10 testInfo.fixme(condition)
Conditionally mark the currently running test as "fixme" with an optional description. This is similar to test.fixme() .
Usage
testInfo.fixme(condition);testInfo.fixme(condition, description);
Arguments
Test is marked as "fixme" when the condition is true.
description string
(optional)#
Optional description that will be reflected in a test report.
Added in: v1.10 testInfo.outputPath
Returns a path inside the testInfo.outputDir where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with each other.
import { test, expect } from '@playwright/test';import fs from 'fs';test('example test', async ({}, testInfo) => { const file = testInfo.outputPath('dir', 'temporary-file.txt'); await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8');});
Note that
pathSegmentsaccepts path segments to the test output directory such astestInfo.outputPath('relative', 'path', 'to', 'output'). However, this path must stay within the testInfo.outputDir directory for each test (i.e.test-results/a-test-title), otherwise it will throw.
Usage
testInfo.outputPath(...pathSegments);
Arguments
Returns
Added in: v1.10 testInfo.setTimeout
Changes the timeout for the currently running test. Zero means no timeout. Learn more about various timeouts .
Timeout is usually specified in the configuration file , but it could be useful to change the timeout in certain scenarios:
import { test, expect } from '@playwright/test';test.beforeEach(async ({ page }, testInfo) => { // Extend timeout for all tests running this hook by 30 seconds. testInfo.setTimeout(testInfo.timeout + 30000);});
Usage
testInfo.setTimeout(timeout);
Arguments
Added in: v1.10 testInfo.skip()
Unconditionally skip the currently running test. Test is immediately aborted. This is similar to test.skip() .
Usage
testInfo.skip();
Added in: v1.10 testInfo.skip(condition)
Conditionally skips the currently running test with an optional description. This is similar to test.skip() .
Usage
testInfo.skip(condition);testInfo.skip(condition, description);
Arguments
A skip condition. Test is skipped when the condition is true.
description string
(optional)#
Optional description that will be reflected in a test report.
Added in: v1.10 testInfo.slow()
Marks the currently running test as "slow", giving it triple the default timeout. This is similar to test.slow() .
Usage
testInfo.slow();
Added in: v1.10 testInfo.slow(condition)
Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default timeout. This is similar to test.slow() .
Usage
testInfo.slow(condition);testInfo.slow(condition, description);
Arguments
Test is marked as "slow" when the condition is true.
description string
(optional)#
Optional description that will be reflected in a test report.
Added in: v1.10 testInfo.snapshotPath
Returns a path to a snapshot file with the given name. Pass kind
to obtain a specific path:
kind: 'screenshot' for expect(page).toHaveScreenshot()
;kind: 'aria' for expect(locator).toMatchAriaSnapshot()
;kind: 'snapshot' for expect(value).toMatchSnapshot()
.Usage
await expect(page).toHaveScreenshot('header.png');// Screenshot assertion above expects screenshot at this path:const screenshotPath = test.info().snapshotPath('header.png', { kind: 'screenshot' });await expect(page.getByRole('main')).toMatchAriaSnapshot({ name: 'main.aria.yml' });// Aria snapshot assertion above expects snapshot at this path:const ariaSnapshotPath = test.info().snapshotPath('main.aria.yml', { kind: 'aria' });expect('some text').toMatchSnapshot('snapshot.txt');// Snapshot assertion above expects snapshot at this path:const snapshotPath = test.info().snapshotPath('snapshot.txt');expect('some text').toMatchSnapshot(['dir', 'subdir', 'snapshot.txt']);// Snapshot assertion above expects snapshot at this path:const nestedPath = test.info().snapshotPath('dir', 'subdir', 'snapshot.txt');
Arguments
The name of the snapshot or the path segments to define the snapshot file path. Snapshots with the same name in the same test file are expected to be the same.
When passing kind , multiple name segments are not supported.
options Object
(optional)
kind "snapshot" | "screenshot" | "aria" (optional) Added in: v1.53#
The snapshot kind controls which snapshot path template is used. See testConfig.snapshotPathTemplate
for more details. Defaults to 'snapshot'.
Returns
Properties
Added in: v1.10 testInfo.annotations
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all test.describe() groups the test belongs to and file-level annotations for the test file.
Learn more about test annotations .
Usage
testInfo.annotations
Type
Added in: v1.10 testInfo.attachments
The list of files or buffers attached to the current test. Some reporters show test attachments.
To add an attachment, use testInfo.attach() instead of directly pushing onto this array.
Usage
testInfo.attachments
Type
name string
Attachment name.
contentType string
Content type of this attachment to properly present in the report, for example 'application/json' or 'image/png'.
path string
(optional)
Optional path on the filesystem to the attached file.
body Buffer
(optional)
Optional attachment body used instead of a file.
Added in: v1.10 testInfo.column
Column number where the currently running test is declared.
Usage
testInfo.column
Type
Added in: v1.10 testInfo.config
Processed configuration from the configuration file .
Usage
testInfo.config
Type
Added in: v1.10 testInfo.duration
The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or not. Can be used in test.afterEach() hook.
Usage
testInfo.duration
Type
Added in: v1.10 testInfo.error
First error thrown during test execution, if any. This is equal to the first element in testInfo.errors .
Usage
testInfo.error
Type
Added in: v1.10 testInfo.errors
Errors thrown during test execution, if any.
Usage
testInfo.errors
Type
Added in: v1.10 testInfo.expectedStatus
Expected status for the currently running test. This is usually 'passed', except for a few cases:
'skipped' for skipped tests, e.g. with test.skip()
;'failed' for tests marked as failed with test.fail()
.Expected status is usually compared with the actual testInfo.status :
import { test, expect } from '@playwright/test';test.afterEach(async ({}, testInfo) => { if (testInfo.status !== testInfo.expectedStatus) console.log(`${testInfo.title} did not run as expected!`);});
Usage
testInfo.expectedStatus
Type
Added in: v1.10 testInfo.file
Absolute path to a file where the currently running test is declared.
Usage
testInfo.file
Type
Added in: v1.10 testInfo.fn
Test function as passed to test(title, testFunction).
Usage
testInfo.fn
Type
Added in: v1.10 testInfo.line
Line number where the currently running test is declared.
Usage
testInfo.line
Type
Added in: v1.10 testInfo.outputDir
Absolute path to the output directory for this specific test run. Each test run gets its own directory so they cannot conflict.
Usage
testInfo.outputDir
Type
Added in: v1.10 testInfo.parallelIndex
The index of the worker between 0 and workers - 1. It is guaranteed that workers running at the same time have a different parallelIndex. When a worker is restarted, for example after a failure, the new worker process has the same parallelIndex.
Also available as process.env.TEST_PARALLEL_INDEX. Learn more about parallelism and sharding
with Playwright Test.
Usage
testInfo.parallelIndex
Type
Added in: v1.10 testInfo.project
Processed project configuration from the configuration file .
Usage
testInfo.project
Type
Added in: v1.10 testInfo.repeatEachIndex
Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing --repeat-each to the command line
.
Usage
testInfo.repeatEachIndex
Type
Added in: v1.10 testInfo.retry
Specifies the retry number when the test is retried after a failure. The first test run has testInfo.retry equal to zero, the first retry has it equal to one, and so on. Learn more about retries .
import { test, expect } from '@playwright/test';test.beforeEach(async ({}, testInfo) => { // You can access testInfo.retry in any hook or fixture. if (testInfo.retry > 0) console.log(`Retrying!`);});test('my test', async ({ page }, testInfo) => { // Here we clear some server-side state when retrying. if (testInfo.retry) await cleanSomeCachesOnTheServer(); // ...});
Usage
testInfo.retry
Type
Added in: v1.10 testInfo.snapshotDir
Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so they cannot conflict.
This property does not account for the testProject.snapshotPathTemplate configuration.
Usage
testInfo.snapshotDir
Type
Added in: v1.10 testInfo.snapshotSuffix
note
Use of testInfo.snapshotSuffix is discouraged. Please use testConfig.snapshotPathTemplate to configure snapshot paths.
Suffix used to differentiate snapshots between multiple test configurations. For example, if snapshots depend on the platform, you can set testInfo.snapshotSuffix equal to process.platform. In this case expect(value).toMatchSnapshot(snapshotName) will use different snapshots depending on the platform. Learn more about snapshots
.
Usage
testInfo.snapshotSuffix
Type
Added in: v1.10 testInfo.status
Actual status for the currently running test. Available after the test has finished in test.afterEach() hook and fixtures.
Status is usually compared with the testInfo.expectedStatus :
import { test, expect } from '@playwright/test';test.afterEach(async ({}, testInfo) => { if (testInfo.status !== testInfo.expectedStatus) console.log(`${testInfo.title} did not run as expected!`);});
Usage
testInfo.status
Type
Added in: v1.43 testInfo.tags
Tags that apply to the test. Learn more about tags .
note
Any changes made to this list while the test is running will not be visible to test reporters.
Usage
testInfo.tags
Type
Added in: v1.32 testInfo.testId
Test id matching the test case id in the reporter API.
Usage
testInfo.testId
Type
Added in: v1.10 testInfo.timeout
Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about various timeouts .
Timeout is usually specified in the configuration file
import { test, expect } from '@playwright/test';test.beforeEach(async ({ page }, testInfo) => { // Extend timeout for all tests running this hook by 30 seconds. testInfo.setTimeout(testInfo.timeout + 30000);});
Usage
testInfo.timeout
Type
Added in: v1.10 testInfo.title
The title of the currently running test as passed to test(title, testFunction).
Usage
testInfo.title
Type
Added in: v1.10 testInfo.titlePath
The full title path starting with the test file name.
Usage
testInfo.titlePath
Type
Added in: v1.10 testInfo.workerIndex
The unique index of the worker process that is running the test. When a worker is restarted, for example after a failure, the new worker process gets a new unique workerIndex.
Also available as process.env.TEST_WORKER_INDEX. Learn more about parallelism and sharding
with Playwright Test.
Usage
testInfo.workerIndex
Type