docs: explain a bit more about fixture boxing and custom titles (#31877)

This commit is contained in:
Dmitry Gozman 2024-07-26 07:43:58 -07:00 committed by GitHub
parent 6988194c97
commit 9227d1c598
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -675,27 +675,30 @@ test('passes', async ({ database, page, a11y }) => {
## Box fixtures ## Box fixtures
You can minimize the fixture exposure to the reporters UI and error messages via boxing it: Usually, custom fixtures are reported as separate steps in in the UI mode, Trace Viewer and various test reports. They also appear in error messages from the test runner. For frequently-used fixtures, this can mean lots of noise. You can stop the fixtures steps from being shown in the UI by "boxing" it.
```js ```js
import { test as base } from '@playwright/test'; import { test as base } from '@playwright/test';
export const test = base.extend({ export const test = base.extend({
_helperFixture: [async ({}, use, testInfo) => { helperFixture: [async ({}, use, testInfo) => {
// ...
}, { box: true }], }, { box: true }],
}); });
``` ```
This is useful for non-interesting helper fixtures. For example, an [automatic](./test-fixtures.md#automatic-fixtures) fixture that sets up some common data can be safely hidden from a test report.
## Custom fixture title ## Custom fixture title
You can assign a custom title to a fixture to be used in error messages and in the Instead of the usual fixture name, you can give fixtures a custom title that will be shown in test reports and error messages.
reporters UI:
```js ```js
import { test as base } from '@playwright/test'; import { test as base } from '@playwright/test';
export const test = base.extend({ export const test = base.extend({
_innerFixture: [async ({}, use, testInfo) => { innerFixture: [async ({}, use, testInfo) => {
// ...
}, { title: 'my fixture' }], }, { title: 'my fixture' }],
}); });
``` ```