Skip to main content
Version: 1.15

TestInfo

TestInfo contains information about currently running test. It is available to any test function, test.beforeEach(hookFunction) and test.afterEach(hookFunction) 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'));});

testInfo.fail([condition, description])#

  • condition <void|boolean> Optional condition - the test is marked as "should fail" when the condition is true.#
  • description <void|string> Optional description that will be reflected in a test report.#
  • returns: <void>#

Marks the currently running test as "should fail". Playwright Test ensures that this test is actually failing. This is similar to test.fail([condition, description]).

testInfo.fixme([condition, description])#

  • condition <void|boolean> Optional condition - the test is marked as "fixme" when the condition is true.#
  • description <void|string> Optional description that will be reflected in a test report.#
  • returns: <void>#

Marks the currently running test as "fixme". The test will be skipped, but the intention is to fix it. This is similar to test.fixme([condition, description]).

testInfo.outputPath(pathSegments)#

  • pathSegments <[string...]> Path segments to append at the end of the resulting path.#
  • returns: <string>#

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');});

testInfo.setTimeout(timeout)#

Changes the timeout for the currently running test. Zero means no timeout.

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);});

testInfo.skip([condition, description])#

  • condition <void|boolean> Optional condition - the test is skipped when the condition is true.#
  • description <void|string> Optional description that will be reflected in a test report.#
  • returns: <void>#

Skips the currently running test. This is similar to test.skip().

testInfo.slow([condition, description])#

  • condition <void|boolean> Optional condition - the test is marked as "slow" when the condition is true.#
  • description <void|string> Optional description that will be reflected in a test report.#
  • returns: <void>#

Marks the currently running test as "slow", giving it triple the default timeout. This is similar to test.slow([condition, description]).

testInfo.snapshotPath(snapshotName)#

Returns a path to a snapshot file with the given snapshotName. Learn more about snapshots.

testInfo.annotations#

The list of annotations applicable to the current test. Includes annotations from the test, annotations from all test.describe(title, callback) groups the test belongs to and file-level annotations for the test file.

Learn more about test annotations.

testInfo.attachments#

  • type: <Array<Object>>
    • 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 <void|string> Optional path on the filesystem to the attached file.
    • body <void|Buffer> Optional attachment body used instead of a file.

The list of files or buffers attached to the current test. Some reporters show test attachments. 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');
  // Capture a screenshot and attach it.  const path = testInfo.outputPath('screenshot.png');  await page.screenshot({ path });  testInfo.attachments.push({ name: 'screenshot', path, contentType: 'image/png' });});

testInfo.column#

Column number where the currently running test is declared.

testInfo.config#

Processed configuration from the configuration file.

testInfo.duration#

The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or not.

testInfo.error#

  • type: <Object>
    • message <void|string> Error message. Set when Error (or its subclass) has been thrown.
    • stack <void|string> Error stack. Set when Error (or its subclass) has been thrown.
    • value <void|string> The thrown value. Set when anything except the Error (or its subclass) has been thrown.

An error thrown during test execution, if any.

testInfo.expectedStatus#

  • type: <"passed"|"failed"|"timedOut"|"skipped">

Expected status for the currently running test. This is usually 'passed', except for a few cases:

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!`);});

testInfo.file#

Absolute path to a file where the currently running test is declared.

testInfo.fn#

Test function as passed to test(title, testFunction).

testInfo.line#

Line number where the currently running test is declared.

testInfo.outputDir#

Absolute path to the output directory for this specific test run. Each test run gets its own directory so they cannot conflict.

testInfo.project#

Processed project configuration from the configuration file.

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.

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.

testInfo.snapshotSuffix#

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.

testInfo.status#

  • type: <void|"passed"|"failed"|"timedOut"|"skipped">

Actual status for the currently running test. Available after the test has finished in test.afterEach(hookFunction) 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!`);});

testInfo.stderr#

Output written to process.stderr or console.error during the test execution.

testInfo.stdout#

Output written to process.stdout or console.log during the test execution.

testInfo.timeout#

Timeout in milliseconds for the currently running test. Zero means no timeout. 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);});

testInfo.title#

The title of the currently running test as passed to test(title, testFunction).

testInfo.workerIndex#

The unique index of the worker process that is running the test. Also available as process.env.TEST_WORKER_INDEX. Learn more about parallelism and sharding with Playwright Test.