diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 9b8d3de31b..a3048de21c 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -1809,6 +1809,8 @@ The list of supported tokens: * Value: `page` * `{testFileName}` - Test file name with extension. * Value: `page-click.spec.ts` +* `{testFileNameWithoutExtension}` - Test file name without extension. + * Value: `page-click` * `{testFilePath}` - Relative path from `testDir` to **test file** * Value: `page/page-click.spec.ts` * `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index b5b1010ff2..1e9d85e9c5 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -454,6 +454,7 @@ export class TestInfoImpl implements TestInfo { .replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '') .replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName()) .replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base) + .replace(/\{(.)?testFileNameWithoutExtension\}/g, '$1' + parsedRelativeTestFilePath.base.replace('.spec', '').replace('.ts', '')) .replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath) .replace(/\{(.)?arg\}/g, '$1' + path.join(parsedSubPath.dir, parsedSubPath.name)) .replace(/\{(.)?ext\}/g, parsedSubPath.ext ? '$1' + parsedSubPath.ext : ''); diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 706d567dcb..323055e142 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -467,6 +467,8 @@ interface TestProject { * - Value: `page` * - `{testFileName}` - Test file name with extension. * - Value: `page-click.spec.ts` + * - `{testFileNameWithoutExtension}` - Test file name without extension. + * - Value: `page-click` * - `{testFilePath}` - Relative path from `testDir` to **test file** * - Value: `page/page-click.spec.ts` * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. @@ -1531,6 +1533,8 @@ interface TestConfig { * - Value: `page` * - `{testFileName}` - Test file name with extension. * - Value: `page-click.spec.ts` + * - `{testFileNameWithoutExtension}` - Test file name without extension. + * - Value: `page-click` * - `{testFilePath}` - Relative path from `testDir` to **test file** * - Value: `page/page-click.spec.ts` * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. diff --git a/tests/playwright-test/snapshot-path-template.spec.ts b/tests/playwright-test/snapshot-path-template.spec.ts index 4f260469b7..65372e1c63 100644 --- a/tests/playwright-test/snapshot-path-template.spec.ts +++ b/tests/playwright-test/snapshot-path-template.spec.ts @@ -79,6 +79,9 @@ test('tokens should expand property', async ({ runInlineTest }, testInfo) => { }, { name: 'testFileName', snapshotPathTemplate: '{testFileName}', + }, { + name: 'testFileNameWithoutExtension', + snapshotPathTemplate: '{testFileNameWithoutExtension}', }, { name: 'snapshotDir', snapshotDir: './a-snapshot-dir',