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
chore: remove refined title (#22541)
Pavel Feldmand95268ffc02f
diff --git a/packages/playwright-test/src/common/ipc.ts b/packages/playwright-test/src/common/ipc.tsindex 7852dcc789..9b3982d445 100644--- a/packages/playwright-test/src/common/ipc.ts+++ b/packages/playwright-test/src/common/ipc.ts@@ -94,7 +94,6 @@ export type StepBeginPayload = {export type StepEndPayload = {testId: string;stepId: string;- refinedTitle?: string;wallTime: number; // milliseconds since unix epocherror?: TestInfoError;};diff --git a/packages/playwright-test/src/matchers/expect.ts b/packages/playwright-test/src/matchers/expect.tsindex 6dba330818..3719a1bab8 100644--- a/packages/playwright-test/src/matchers/expect.ts+++ b/packages/playwright-test/src/matchers/expect.ts@@ -46,7 +46,7 @@ import {toHaveValues,toPass} from './matchers';-import { toMatchSnapshot, toHaveScreenshot } from './toMatchSnapshot';+import { toMatchSnapshot, toHaveScreenshot, toHaveScreenshotStepTitle } from './toMatchSnapshot';import type { Expect } from '../../types/test';import { currentTestInfo, currentExpectTimeout } from '../common/globals';import { filteredStackTrace, serializeError, stringifyStackFrames, trimLongString } from '../util';@@ -210,7 +210,9 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {const rawStack = captureRawStack();const stackFrames = filteredStackTrace(rawStack);const customMessage = this._info.message || '';- const defaultTitle = `expect${this._info.isPoll ? '.poll' : ''}${this._info.isSoft ? '.soft' : ''}${this._info.isNot ? '.not' : ''}.${matcherName}`;+ const argsSuffix = computeArgsSuffix(matcherName, args);++ const defaultTitle = `expect${this._info.isPoll ? '.poll' : ''}${this._info.isSoft ? '.soft' : ''}${this._info.isNot ? '.not' : ''}.${matcherName}${argsSuffix}`;const wallTime = Date.now();const step = testInfo._addStep({location: stackFrames[0],@@ -218,7 +220,6 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {title: trimLongString(customMessage || defaultTitle, 1024),wallTime});- testInfo.currentStep = step;const generateTraceEvent = matcherName !== 'poll' && matcherName !== 'toPass';const callId = ++lastCallId;@@ -314,4 +315,11 @@ async function pollMatcher(matcherName: any, isNot: boolean, pollIntervals: numb}}+function computeArgsSuffix(matcherName: string, args: any[]) {+ let value = '';+ if (matcherName === 'toHaveScreenshot')+ value = toHaveScreenshotStepTitle(...args);+ return value ? `(${value})` : '';+}+expectLibrary.extend(customMatchers);diff --git a/packages/playwright-test/src/matchers/toMatchSnapshot.ts b/packages/playwright-test/src/matchers/toMatchSnapshot.tsindex 05eff09ca1..7380a56f92 100644--- a/packages/playwright-test/src/matchers/toMatchSnapshot.ts+++ b/packages/playwright-test/src/matchers/toMatchSnapshot.ts@@ -110,7 +110,6 @@ class SnapshotHelper<T extends ImageComparatorOptions> {}}- testInfo.currentStep!.refinedTitle = `${testInfo.currentStep!.title}(${path.basename(this.snapshotName)})`;options = {...configOptions,...options,@@ -288,6 +287,18 @@ export function toMatchSnapshot(type HaveScreenshotOptions = ImageComparatorOptions & Omit<PageScreenshotOptions, 'type' | 'quality' | 'path'>;+export function toHaveScreenshotStepTitle(+ nameOrOptions: NameOrSegments | { name?: NameOrSegments } & HaveScreenshotOptions = {},+ optOptions: HaveScreenshotOptions = {}+): string {+ let name: NameOrSegments | undefined;+ if (typeof nameOrOptions === 'object' && !Array.isArray(nameOrOptions))+ name = nameOrOptions.name;+ else+ name = nameOrOptions;+ return Array.isArray(name) ? name.join(path.sep) : name || '';+}+export async function toHaveScreenshot(this: ReturnType<Expect['getState']>,pageOrLocator: Page | Locator,diff --git a/packages/playwright-test/src/runner/dispatcher.ts b/packages/playwright-test/src/runner/dispatcher.tsindex 17dbc1aae8..29bc40375f 100644--- a/packages/playwright-test/src/runner/dispatcher.ts+++ b/packages/playwright-test/src/runner/dispatcher.ts@@ -301,8 +301,6 @@ export class Dispatcher {this._reporter.onStdErr?.('Internal error: step end without step begin: ' + params.stepId, data.test, result);return;}- if (params.refinedTitle)- step.title = params.refinedTitle;step.duration = params.wallTime - step.startTime.getTime();if (params.error)step.error = params.error;diff --git a/packages/playwright-test/src/worker/testInfo.ts b/packages/playwright-test/src/worker/testInfo.tsindex 553cc8a24e..51f29eb790 100644--- a/packages/playwright-test/src/worker/testInfo.ts+++ b/packages/playwright-test/src/worker/testInfo.ts@@ -33,7 +33,6 @@ interface TestStepInternal {category: string;wallTime: number;location?: Location;- refinedTitle?: string;}export class TestInfoImpl implements TestInfo {@@ -77,7 +76,6 @@ export class TestInfoImpl implements TestInfo {readonly outputDir: string;readonly snapshotDir: string;errors: TestInfoError[] = [];- currentStep: TestStepInternal | undefined;get error(): TestInfoError | undefined {return this.errors[0];@@ -234,7 +232,6 @@ export class TestInfoImpl implements TestInfo {}const payload: StepEndPayload = {testId: this._test.id,- refinedTitle: step.refinedTitle,stepId,wallTime: Date.now(),error,diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.tsindex 491a446cef..dfd4e4a0c1 100644--- a/tests/playwright-test/to-have-screenshot.spec.ts+++ b/tests/playwright-test/to-have-screenshot.spec.ts@@ -199,8 +199,7 @@ test('should report toHaveScreenshot step with expectation name in title', asynctest('is a test', async ({ page }) => {// Named expectation.await expect(page).toHaveScreenshot('foo.png', { timeout: 2000 });- // Anonymous expectation.- await expect(page).toHaveScreenshot({ timeout: 2000 });+ await expect(page).toHaveScreenshot({ name: 'is-a-test-1.png', timeout: 2000 });});`}, { 'reporter': '', 'workers': 1, 'update-snapshots': true });