`TestInfo` contains information about currently running test. It is available to any test function, [`method: Test.beforeEach`] and [`method: Test.afterEach`] 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.
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe`] groups the test belongs to and file-level annotations for the test file.
Learn more about [test annotations](./test-annotations.md).
## property: 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.
To safely add a file from disk as an attachment, please use [`method: TestInfo.attach#1`] instead of directly pushing onto this array. For inline attachments, use [`method: TestInfo.attach#1`].
## method: TestInfo.attach#1
Attach a file from disk to the current test. Some reporters show test attachments. The [`option: name`] and [`option: contentType`] will be inferred by default from the [`param: path`], but you can optionally override either of these.
For example, you can attach a screenshot to the test:
[`method: TestInfo.attach#1`] automatically takes care of copying attachments to a
location that is accessible to reporters, even if you were to delete the attachment
after awaiting the attach call.
:::
### param: TestInfo.attach#1.path
-`path`<[string]> Path on the filesystem to the attached file.
### option: TestInfo.attach#1.name
-`name`<[void]|[string]> Optional attachment name. If omitted, this will be inferred from [`param: path`].
### option: TestInfo.attach#1.contentType
-`contentType`<[void]|[string]> Optional content type of this attachment to properly present in the report, for example `'application/json'` or `'image/png'`. If omitted, this falls back to an inferred type based on the [`param: name`] (if set) or [`param: path`]'s extension; it will be set to `application/octet-stream` if the type cannot be inferred from the file extension.
## method: TestInfo.attach#2
Attach data to the current test, either a `string` or a `Buffer`. Some reporters show test attachments.
### param: TestInfo.attach#2.body
-`body`<[string]|[Buffer]> Attachment body.
### param: TestInfo.attach#2.name
-`name`<[string]> Attachment name.
### option: TestInfo.attach#2.contentType
-`contentType`<[void]|[string]> Optional content type of this attachment to properly present in the report, for example `'application/json'` or `'application/xml'`. If omitted, this falls back to an inferred type based on the [`param: name`]'s extension; if the type cannot be inferred from the name's extension, it will be set to `text/plain` (if [`param: body`] is a `string`) or `application/octet-stream` (if [`param: body`] is a `Buffer`).
The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or not. Can be used in [`method: Test.afterEach`] hook.
console.log(`${testInfo.title} did not run as expected!`);
});
```
```js js-flavor=ts
import { test, expect } from '@playwright/test';
test.afterEach(async ({}, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus)
console.log(`${testInfo.title} did not run as expected!`);
});
```
## method: TestInfo.fail
Marks the currently running test as "should fail". Playwright Test ensures that this test is actually failing. This is similar to [`method: Test.fail`].
### param: TestInfo.fail.condition
-`condition`<[void]|[boolean]>
Optional condition - the test is marked as "should fail" when the condition is `true`.
### param: TestInfo.fail.description
-`description`<[void]|[string]>
Optional description that will be reflected in a test report.
## property: TestInfo.file
- type: <[string]>
Absolute path to a file where the currently running test is declared.
Absolute path to the output directory for this specific test run. Each test run gets its own directory so they cannot conflict.
## method: TestInfo.outputPath
- returns: <[string]>
Returns a path inside the [`property: TestInfo.outputDir`] where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with each other.
> Note that `pathSegments` accepts path segments to the test output directory such as `testInfo.outputPath('relative', 'path', 'to', 'output')`.
> However, this path must stay within the [`property: TestInfo.outputDir`] directory for each test (i.e. `test-results/a-test-title`), otherwise it will throw.
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](./test-parallel.md) with Playwright Test.
Processed project configuration from the [configuration file](./test-configuration.md).
## property: TestInfo.repeatEachIndex
- type: <[int]>
Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each` to the [command line](./test-cli.md).
Specifies the retry number when the test is retried after a failure. The first test run has [`property: TestInfo.retry`] equal to zero, the first retry has it equal to one, and so on. Learn more about [retries](./test-retries.md#retries).
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.
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](./test-snapshots.md).
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](./test-parallel.md) with Playwright Test.