Skip to content

[pull] main from microsoft:main #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/test-api/class-teststepinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ A skip condition. Test step is skipped when the condition is `true`.
- `description` ?<[string]>

Optional description that will be reflected in a test report.

## property: TestStepInfo.titlePath
* since: v1.55
- type: <[Array]<[string]>>

The full title path starting with the test file name, including the step titles. See also [`property: TestInfo.titlePath`].
8 changes: 4 additions & 4 deletions packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
{
"name": "chromium-tip-of-tree",
"revision": "1350",
"revision": "1351",
"installByDefault": false,
"browserVersion": "140.0.7301.0"
"browserVersion": "140.0.7311.0"
},
{
"name": "chromium-tip-of-tree-headless-shell",
"revision": "1350",
"revision": "1351",
"installByDefault": false,
"browserVersion": "140.0.7301.0"
"browserVersion": "140.0.7311.0"
},
{
"name": "firefox",
Expand Down
13 changes: 11 additions & 2 deletions packages/playwright/src/worker/testInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class TestInfoImpl implements TestInfo {
...data,
steps: [],
attachmentIndices,
info: new TestStepInfoImpl(this, stepId),
info: new TestStepInfoImpl(this, stepId, data.title, parentStep?.info),
complete: result => {
if (step.endWallTime)
return;
Expand Down Expand Up @@ -589,12 +589,16 @@ export class TestStepInfoImpl implements TestStepInfo {

private _testInfo: TestInfoImpl;
private _stepId: string;
private _title: string;
private _parentStep?: TestStepInfoImpl;

skip: (arg?: any, description?: string) => void;

constructor(testInfo: TestInfoImpl, stepId: string) {
constructor(testInfo: TestInfoImpl, stepId: string, title: string, parentStep?: TestStepInfoImpl) {
this._testInfo = testInfo;
this._stepId = stepId;
this._title = title;
this._parentStep = parentStep;
this.skip = wrapFunctionWithLocation((location: Location, ...args: unknown[]) => {
// skip();
// skip(condition: boolean, description: string);
Expand Down Expand Up @@ -627,6 +631,11 @@ export class TestStepInfoImpl implements TestStepInfo {
async attach(name: string, options?: { body?: string | Buffer; contentType?: string; path?: string; }): Promise<void> {
this._attachToStep(await normalizeAndSaveAttachment(this._testInfo.outputPath(), name, options));
}

get titlePath(): string[] {
const parent = this._parentStep ?? this._testInfo;
return [...parent.titlePath, this._title];
}
}

export class TestSkipError extends Error {
Expand Down
6 changes: 6 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9914,6 +9914,12 @@ export interface TestStepInfo {
* @param description Optional description that will be reflected in a test report.
*/
skip(condition: boolean, description?: string): void;

/**
* 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).
*/
titlePath: Array<string>;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/playwright-test/test-step.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,38 @@ hook |After Hooks
`);
});

test('step.titlePath works in custom matcher', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36739' } }, async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
import { test, expect as baseExpect } from '@playwright/test';
const expect = baseExpect.extend({
async toHaveTitlePath(receiver, expected: string[]) {
return await test.step('get titlepath', async step => {
const actual = step.titlePath;
try {
expect(actual).toEqual(expected);
return { name: 'toHaveTitlePath', pass: true, message: '' };
} catch {
return { name: 'toHaveTitlePath', pass: false, message: () => \`Expected \${JSON.stringify(expected)}, got \${JSON.stringify(actual)}\` };
}
});
},
});
test('test', async ({ }) => {
await expect().toHaveTitlePath(['a.test.ts', 'test', 'toHaveTitlePath', 'get titlepath']);
await test.step('outer step', async () => {
await expect().toHaveTitlePath(['a.test.ts', 'test', 'outer step', 'toHaveTitlePath', 'get titlepath']);
await test.step('inner step', async () => {
await expect().toHaveTitlePath(['a.test.ts', 'test', 'outer step', 'inner step', 'toHaveTitlePath', 'get titlepath']);
});
});
});
`
}, { reporter: '' });

expect(result.exitCode).toBe(0);
});

test('should differentiate test.skip and step.skip', async ({ runInlineTest }) => {
const result = await runInlineTest({
'reporter.ts': stepIndentReporter,
Expand Down
Loading