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(test): add annotations to TestStepInfo (#42388)
Copilotdeda92d15e7d
diff --git a/docs/src/test-api/class-teststepinfo.md b/docs/src/test-api/class-teststepinfo.mdindex 34abfaf0bf..2b1079cce7 100644--- a/docs/src/test-api/class-teststepinfo.md+++ b/docs/src/test-api/class-teststepinfo.md@@ -15,6 +15,15 @@ test('basic test', async ({ page, browserName }) => {});```+## property: TestStepInfo.annotations+* since: v1.58+- type: <[Array]<[Object]>>+ - `type` <[string]> Annotation type, for example `'skip'`.+ - `description` ?<[string]> Optional description.+ - `location` ?<[Location]> Optional location in the source where the annotation is added.++The list of annotations applicable to the current test step.+## async method: TestStepInfo.attach* since: v1.51diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex d4592cc1d0..03c9cdc361 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -10810,6 +10810,26 @@ export interface TestStepInfo {*/skip(condition: boolean, description?: string): void;+ /**+ * The list of annotations applicable to the current test step.+ */+ annotations: Array<{+ /**+ * Annotation type, for example `'skip'`.+ */+ type: string;++ /**+ * Optional description.+ */+ description?: string;++ /**+ * Optional location in the source where the annotation is added.+ */+ location?: Location;+ }>;+/*** The full title path starting with the test file name, including the step titles. See also* [testInfo.titlePath](https://playwright.dev/docs/api/class-testinfo#test-info-title-path).diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.tsindex 851148ead8..3199c45c18 100644--- a/tests/playwright-test/reporter.spec.ts+++ b/tests/playwright-test/reporter.spec.ts@@ -795,6 +795,31 @@ test('step attachments are referentially equal to result attachments', async ({]);});+test('step annotations are reported in onStepEnd', async ({ runInlineTest }) => {+ class TestReporter implements Reporter {+ onStepEnd(test: TestCase, result: TestResult, step: TestStep) {+ if (step.category === 'test.step')+ console.log('%%%', JSON.stringify(step.annotations));+ }+ }+ const result = await runInlineTest({+ 'reporter.ts': `module.exports = ${TestReporter.toString()}`,+ 'playwright.config.ts': `module.exports = { reporter: './reporter' };`,+ 'a.spec.ts': `+ import { test } from '@playwright/test';+ test('test', async () => {+ await test.step('step', async stepInfo => {+ stepInfo.annotations.push({ type: 'expected-result', description: 'step passes' });+ });+ });+ `,+ }, { 'reporter': '', 'workers': 1 });++ expect(result.outputLines).toEqual([+ JSON.stringify([{ type: 'expected-result', description: 'step passes' }]),+ ]);+});+test('step.attach attachments are reported on right steps', async ({ runInlineTest }) => {class TestReporter implements Reporter {onStepEnd(test: TestCase, result: TestResult, step: TestStep) {diff --git a/tests/playwright-test/types-2.spec.ts b/tests/playwright-test/types-2.spec.tsindex 79b36aacdc..6fb76ec658 100644--- a/tests/playwright-test/types-2.spec.ts+++ b/tests/playwright-test/types-2.spec.ts@@ -28,6 +28,9 @@ test('basics should work', async ({ runTSC }) => {test('my test', async({}, testInfo) => {expect(testInfo.title).toBe('my test');testInfo.annotations[0].type;+ await test.step('step', async stepInfo => {+ stepInfo.annotations.push({ type: 'expected-result', description: 'step passes' });+ });test.setTimeout(123);testInfo.snapshotPath('a', 'b');testInfo.snapshotPath();