Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat: exposes tags in testInfo (#29794)
Lukas Bockstaller425f737eb6ac
diff --git a/docs/src/test-api/class-testinfo.md b/docs/src/test-api/class-testinfo.mdindex d766920b06..97e9c16ebf 100644--- a/docs/src/test-api/class-testinfo.md+++ b/docs/src/test-api/class-testinfo.md@@ -210,6 +210,14 @@ Optional description that will be reflected in a test report.Test function as passed to `test(title, testFunction)`.+## property: TestInfo.tags+* since: v1.43+- type: <[Array]<[string]>>++Tags that apply to the test. Learn more about [tags](../test-annotations.md#tag-tests).++Note that any changes made to this list while the test is running will not be visible to test reporters.+## property: TestInfo.testId* since: v1.32- type: <[string]>diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.tsindex 70880af1c2..4678812759 100644--- a/packages/playwright/src/worker/testInfo.ts+++ b/packages/playwright/src/worker/testInfo.ts@@ -92,6 +92,7 @@ export class TestInfoImpl implements TestInfo {readonly titlePath: string[];readonly file: string;readonly line: number;+ readonly tags: string[];readonly column: number;readonly fn: Function;expectedStatus: TestStatus;@@ -167,6 +168,7 @@ export class TestInfoImpl implements TestInfo {this.file = test?.location.file ?? '';this.line = test?.location.line ?? 0;this.column = test?.location.column ?? 0;+ this.tags = test?.tags ?? [];this.fn = test?.fn ?? (() => {});this.expectedStatus = test?.expectedStatus ?? 'skipped';diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex 1e610baf53..497b137774 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -2312,6 +2312,13 @@ export interface TestInfo {*/status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";+ /**+ * Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests).+ *+ * Note that any changes made to this list while the test is running will not be visible to test reporters.+ */+ tags: Array<string>;+/*** Test id matching the test case id in the reporter API.*/diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.tsindex 825068f51f..7850a52f07 100644--- a/tests/playwright-test/playwright-test-fixtures.ts+++ b/tests/playwright-test/playwright-test-fixtures.ts@@ -254,8 +254,8 @@ type Fixtures = {};export const test = base- .extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures)- .extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)+ .extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures as any)+ .extend<ServerFixtures, ServerWorkerOptions>(serverFixtures as any).extend<Fixtures>({writeFiles: async ({}, use, testInfo) => {await use(files => writeFiles(testInfo, files, false));@@ -455,4 +455,4 @@ export default defineConfig({},projects: [{name: 'default'}],});-`;\ No newline at end of file+`;diff --git a/tests/playwright-test/test-tag.spec.ts b/tests/playwright-test/test-tag.spec.tsindex e442c2acaa..9259e3b1c6 100644--- a/tests/playwright-test/test-tag.spec.ts+++ b/tests/playwright-test/test-tag.spec.ts@@ -146,3 +146,32 @@ test('should enforce @ symbol', async ({ runInlineTest }) => {expect(result.exitCode).toBe(1);expect(result.output).toContain(`Error: Tag must start with "@" symbol, got "foo" instead.`);});++test('should be included in testInfo', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ test('test without tag', async ({}, testInfo) => {+ expect(testInfo.tags).toStrictEqual([]);+ });+ test('test with tag',{ tag: '@tag1' }, async ({}, testInfo) => {+ expect(testInfo.tags).toStrictEqual(["@tag1"]);+ });+ `,+ });+ expect(result.exitCode).toBe(0);+});++test('should be included in testInfo if comming from describe', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ test.describe('describe with tag', { tag: '@tag2' }, async ()=>{+ test('test with tag', async ({}, testInfo) => {+ expect(testInfo.tags).toStrictEqual(["@tag2"]);+ });+ });+ `,+ });+ expect(result.exitCode).toBe(0);+});