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 runner): allow to pass arbitrary location to test.step (#32504)
오소현8761dafc7365
diff --git a/docs/src/test-api/class-test.md b/docs/src/test-api/class-test.mdindex 9b56fbf2e6..b6ae7d1522 100644--- a/docs/src/test-api/class-test.md+++ b/docs/src/test-api/class-test.md@@ -1710,6 +1710,11 @@ Step body.Whether to box the step in the report. Defaults to `false`. When the step is boxed, errors thrown from the step internals point to the step call site. See below for more details.+### option: Test.step.location+* since: v1.48+- `location` <[Location]>+Specifies a custom location for the step to be shown in test reports. By default, location of the [`method: Test.step`] call is shown.+## method: Test.use* since: v1.10diff --git a/packages/playwright/src/common/testType.ts b/packages/playwright/src/common/testType.tsindex 5c7850a3df..f0882735dc 100644--- a/packages/playwright/src/common/testType.ts+++ b/packages/playwright/src/common/testType.ts@@ -259,11 +259,11 @@ export class TestTypeImpl {suite._use.push({ fixtures, location });}- async _step<T>(title: string, body: () => Promise<T>, options: { box?: boolean } = {}): Promise<T> {+ async _step<T>(title: string, body: () => Promise<T>, options: {box?: boolean, location?: Location } = {}): Promise<T> {const testInfo = currentTestInfo();if (!testInfo)throw new Error(`test.step() can only be called from a test`);- const step = testInfo._addStep({ category: 'test.step', title, box: options.box });+ const step = testInfo._addStep({ category: 'test.step', title, location: options.location, box: options.box });return await zones.run('stepZone', step, async () => {try {const result = await body();diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex e17a43843c..51a6720a2e 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -4703,7 +4703,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue* @param body Step body.* @param options*/- step<T>(title: string, body: () => T | Promise<T>, options?: { box?: boolean }): Promise<T>;+ step<T>(title: string, body: () => T | Promise<T>, options?: { box?: boolean, location?: Location }): Promise<T>;/*** `expect` function can be used to create test assertions. Read more about [test assertions](https://playwright.dev/docs/test-assertions).*diff --git a/tests/playwright-test/test-step.spec.ts b/tests/playwright-test/test-step.spec.tsindex d14bccd98b..ad3478b112 100644--- a/tests/playwright-test/test-step.spec.ts+++ b/tests/playwright-test/test-step.spec.ts@@ -1246,3 +1246,42 @@ fixture | fixture: pagefixture | fixture: context`);});++test('test location to test.step', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'reporter.ts': stepIndentReporter,+ 'helper.ts': `+ import { test } from '@playwright/test';++ export async function dummyStep(test, title, action, location) {+ return await test.step(title, action, { location });+ }++ export function getCustomLocation() {+ return { file: 'dummy-file.ts', line: 123, column: 45 };+ }+ `,+ 'playwright.config.ts': `+ module.exports = {+ reporter: './reporter',+ };+ `,+ 'a.test.ts': `+ import { test } from '@playwright/test';+ import { dummyStep, getCustomLocation } from './helper';++ test('custom location test', async () => {+ const location = getCustomLocation();+ await dummyStep(test, 'Perform a dummy step', async () => {+ }, location);+ });+ `+ }, { reporter: '', workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(stripAnsi(result.output)).toBe(`+hook |Before Hooks+test.step |Perform a dummy step @ dummy-file.ts:123+hook |After Hooks+`);+});\ No newline at end of filediff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex 90ef7fa75a..be1fa7ee37 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -128,7 +128,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValueafterAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;afterAll(title: string, inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;use(fixtures: Fixtures<{}, {}, TestArgs, WorkerArgs>): void;- step<T>(title: string, body: () => T | Promise<T>, options?: { box?: boolean }): Promise<T>;+ step<T>(title: string, body: () => T | Promise<T>, options?: { box?: boolean, location?: Location }): Promise<T>;expect: Expect<{}>;extend<T extends KeyValue, W extends KeyValue = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>;info(): TestInfo;