diff --git a/docs/src/api/params.md b/docs/src/api/params.md index b976e9ac65878..6ae707e8275fe 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -1933,6 +1933,8 @@ The list of supported tokens: * Value: `/home/playwright/tests` (absolute path since `testDir` is resolved relative to directory with config) * `{testFileDir}` - Directories in relative path from `testDir` to **test file**. * Value: `page` +* `{testFileBaseName}` - Test file name without the last extension. + * Value: `page-click.spec` * `{testFileName}` - Test file name with extension. * Value: `page-click.spec.ts` * `{testFilePath}` - Relative path from `testDir` to **test file**. diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index c85c7bca8cdb4..43003ee9e79d5 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -625,6 +625,7 @@ export class TestInfoImpl implements TestInfo { .replace(/\{(.)?platform\}/g, '$1' + process.platform) .replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '') .replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName()) + .replace(/\{(.)?testFileBaseName\}/g, '$1' + parsedRelativeTestFilePath.name) .replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base) .replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath) .replace(/\{(.)?arg\}/g, '$1' + nameArgument) diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index d0b1557c0b292..f68d89e0a792e 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -529,6 +529,8 @@ interface TestProject { * config) * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**. * - Value: `page` + * - `{testFileBaseName}` - Test file name without the last extension. + * - Value: `page-click.spec` * - `{testFileName}` - Test file name with extension. * - Value: `page-click.spec.ts` * - `{testFilePath}` - Relative path from `testDir` to **test file**. @@ -1770,6 +1772,8 @@ interface TestConfig { * config) * - `{testFileDir}` - Directories in relative path from `testDir` to **test file**. * - Value: `page` + * - `{testFileBaseName}` - Test file name without the last extension. + * - Value: `page-click.spec` * - `{testFileName}` - Test file name with extension. * - Value: `page-click.spec.ts` * - `{testFilePath}` - Relative path from `testDir` to **test file**. diff --git a/tests/playwright-test/snapshot-path-template.spec.ts b/tests/playwright-test/snapshot-path-template.spec.ts index f1224b956347f..b454473cc3bb7 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: 'testFileBaseName', + snapshotPathTemplate: '{testFileBaseName}', }, { name: 'snapshotDir', snapshotDir: './a-snapshot-dir', @@ -101,6 +104,7 @@ test('tokens should expand property', async ({ runInlineTest }, testInfo) => { expect.soft(snapshotPath['testFileDir']).toBe(path.join('a', 'b', 'c')); expect.soft(snapshotPath['testFilePath']).toBe(path.join('a', 'b', 'c', 'd.spec.ts')); expect.soft(snapshotPath['testFileName']).toBe('d.spec.ts'); + expect.soft(snapshotPath['testFileBaseName']).toBe('d.spec'); expect.soft(snapshotPath['snapshotDir']).toBe('a-snapshot-dir.png'); expect.soft(snapshotPath['snapshotSuffix']).toBe('-' + process.platform); expect.soft(snapshotPath['testName']).toBe('suite-test-should-work');