feat(playwright-test): introduce snapshotPathTemplate configuration#18568
Merged
Conversation
dgozman
reviewed
Nov 4, 2022
This configuration option allows to set a string with template
values for precise control over snapshot path location.
An example of `snapshotPathTemplate` usage:
```ts
// playwright.config.ts
// Notice the `testDir` configuration!
export default {
testDir: './tests',
snapshotPathTemplate: './__screenshots__/{platform}/{projectName}/{testFilePath}/{snapshotName}',
}
```
Currently supported "magic tokens" inside the `snapshotPathTemplate`
are:
- `{testDir}` - project's `testDir`
- `{snapshotDir}` - project's `snapshotDir`
- `{platform}` - `process.platform`
- `{projectName}` - Project's sanitized name
- `{testFileDir}` - Directories in relative path from `testDir` to test
file path (e.g. `page/` in the example below)
- `{testFileName}` - Test file name (with extension) (e.g.
`page-click.spec.ts` in the example below)
- `{testFilePath}` - Relative path from `testDir` to test file path
(e.g. `page/page-click.spec.ts` in the example below)
- `{snapshotNameDir}` - Relative snapshot name directory (e.g.
`foo/bar/` in the example below)
- `{snapshotNameBase}` - Snapshot name base (e.g. `baz` in the example
below)
- `{snapshotNameExt}` - Snapshot name extension including `.` (e.g.
`.png` in the example below)
- `{snapshotName}` - Snapshot name (e.g. `baz.png` in the example below)
- `{snapshotSuffix}` - `testInfo.snapshotSuffix` value.
Consider the following file structure:
```
playwright.config.ts
tests/
└── page/
└── page-click.spec.ts
```
The following `page-click.spec.ts`:
```ts
// page-click.spec.ts
import { test, expect } from '@playwright/test';
test('should work', async ({ page }) => {
await expect(page).toHaveScreenshot('foo', 'bar', 'baz.png');
});
```
5f98729 to
47bec45
Compare
dgozman
approved these changes
Nov 9, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This configuration option allows to set a string with template
values for precise control over snapshot path location.
An example of
snapshotPathTemplateusage:Currently supported "magic tokens" inside the
snapshotPathTemplateare:
{testDir}- project'stestDir{snapshotDir}- project'ssnapshotDir{platform}-process.platform{projectName}- Project's sanitized name{testFileDir}- Directories in relative path fromtestDirto testfile path (e.g.
page/in the example below){testFileName}- Test file name (with extension) (e.g.page-click.spec.tsin the example below){testFilePath}- Relative path fromtestDirto test file path(e.g.
page/page-click.spec.tsin the example below){ext}- snapshot extension (with dots){arg}- joined snapshot name parts, without extension (e.g.foo/bar/bazin the example below){snapshotSuffix}-testInfo.snapshotSuffixvalue.Consider the following file structure:
The following
page-click.spec.ts:Fixes #7792