new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · Test runner API · all subjects

test info & lifecycle

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

test.info() returns information about currently running test

test.info() returns TestInfo object with information about the currently running test. Can only be called during test execution, throws otherwise. Allows access to test metadata and lifecycle information.

test.info() to attach screenshot

test('example test', async ({ page }) => { // ... await test.info().attach('screenshot', { body: await page.screenshot(), contentType: 'image/png', }); });

TestStepInfo.attach method

The attach method attaches a value or file from disk to the current test step. Either path or body must be specified, but not both. Some reporters show test step attachments. The method automatically copies attached files to a location accessible to reporters, so files can be safely removed after awaiting the attach call. Available since v1.51.

TestStepInfo.attach parameters and options

TestStepInfo.attach has: name (string, required) - attachment name sanitized and used as file prefix; body (string or Buffer, optional) - attachment body, mutually exclusive with path; path (string, optional) - filesystem path to attached file, mutually exclusive with body; contentType (string, optional) - content type for report display (e.g. 'application/json', 'image/png'), defaults to text/plain for strings and application/octet-stream for Buffer if omitted.

TestStepInfo.attach example with screenshot

Example showing how to attach a screenshot to a test step: ```js import { test, expect } from '@playwright/test'; test('basic test', async ({ page }) => { await page.goto('https://playwright.dev'); await test.step('check page rendering', async step => { const screenshot = await page.screenshot(); await step.attach('screenshot', { body: screenshot, contentType: 'image/png' }); }); }); ```

TestStepInfo.attach example with file path

Example showing how to attach files from disk to a test step: ```js import { test, expect } from '@playwright/test'; import { download } from './my-custom-helpers'; test('basic test', async ({}) => { await test.step('check download behavior', async step => { const tmpPath = await download('a'); await step.attach('downloaded', { path: tmpPath }); }); }); ```

TestStepInfo.titlePath property

TestStepInfo.titlePath is an array of strings representing the full title path starting with the test file name, including the step titles. Available since v1.55.

Give your agent this brain