2021-09-14 03:49:58 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { test, expect } from './playwright-test-fixtures';
|
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
const stepHierarchyReporter = `
|
2023-09-29 19:44:00 +03:00
|
|
|
const asciiRegex = new RegExp('[\\\\u001B\\\\u009B][[\\\\]()#;?]*(?:(?:(?:[a-zA-Z\\\\d]*(?:;[-a-zA-Z\\\\d\\\\/#&.:=?%@~_]*)*)?\\\\u0007)|(?:(?:\\\\d{1,4}(?:;\\\\d{0,4})*)?[\\\\dA-PR-TZcf-ntqry=><~]))', 'g');
|
|
|
|
export function stripAnsi(str) {
|
|
|
|
return str.replace(asciiRegex, '');
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
class Reporter {
|
|
|
|
onBegin(config: FullConfig, suite: Suite) {
|
|
|
|
this.suite = suite;
|
|
|
|
}
|
2021-09-14 03:49:58 +03:00
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
distillStep(step) {
|
|
|
|
return {
|
|
|
|
...step,
|
|
|
|
startTime: undefined,
|
|
|
|
duration: undefined,
|
|
|
|
parent: undefined,
|
|
|
|
data: undefined,
|
2021-10-19 07:06:18 +03:00
|
|
|
location: step.location ? {
|
|
|
|
file: step.location.file.substring(step.location.file.lastIndexOf(require('path').sep) + 1).replace('.js', '.ts'),
|
2023-09-29 19:44:00 +03:00
|
|
|
line: step.location.line,
|
|
|
|
column: step.location.column
|
2021-10-19 07:06:18 +03:00
|
|
|
} : undefined,
|
2021-09-17 01:51:27 +03:00
|
|
|
steps: step.steps.length ? step.steps.map(s => this.distillStep(s)) : undefined,
|
2023-09-29 19:44:00 +03:00
|
|
|
error: step.error ? stripAnsi(step.error.stack || '') : undefined,
|
2021-09-17 01:51:27 +03:00
|
|
|
};
|
|
|
|
}
|
2021-09-14 03:49:58 +03:00
|
|
|
|
2023-04-20 03:31:07 +03:00
|
|
|
onStdOut(data) {
|
|
|
|
process.stdout.write(data.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
onStdErr(data) {
|
|
|
|
process.stderr.write(data.toString());
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
async onEnd() {
|
|
|
|
const processSuite = (suite: Suite) => {
|
|
|
|
for (const child of suite.suites)
|
|
|
|
processSuite(child);
|
|
|
|
for (const test of suite.tests) {
|
|
|
|
for (const result of test.results) {
|
|
|
|
for (const step of result.steps) {
|
|
|
|
console.log('%% ' + JSON.stringify(this.distillStep(step)));
|
2021-09-14 03:49:58 +03:00
|
|
|
}
|
2021-09-17 01:51:27 +03:00
|
|
|
}
|
2021-09-14 03:49:58 +03:00
|
|
|
}
|
2021-09-17 01:51:27 +03:00
|
|
|
};
|
|
|
|
processSuite(this.suite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Reporter;
|
|
|
|
`;
|
2021-09-14 03:49:58 +03:00
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
test('should report api step hierarchy', async ({ runInlineTest }) => {
|
2021-09-14 03:49:58 +03:00
|
|
|
const result = await runInlineTest({
|
2021-09-17 01:51:27 +03:00
|
|
|
'reporter.ts': stepHierarchyReporter,
|
2021-09-14 03:49:58 +03:00
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2021-09-14 03:49:58 +03:00
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
await test.step('outer step 1', async () => {
|
|
|
|
await test.step('inner step 1.1', async () => {});
|
|
|
|
await test.step('inner step 1.2', async () => {});
|
|
|
|
});
|
|
|
|
await test.step('outer step 2', async () => {
|
|
|
|
await test.step('inner step 2.1', async () => {});
|
|
|
|
await test.step('inner step 2.2', async () => {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2021-09-14 03:49:58 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
steps: [
|
2023-04-28 18:57:43 +03:00
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserType.launch',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newContext',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserContext.newPage',
|
|
|
|
},
|
|
|
|
]
|
2021-09-14 03:49:58 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'outer step 1',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
title: 'inner step 1.1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
title: 'inner step 1.2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'outer step 2',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
title: 'inner step 2.1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
title: 'inner step 2.2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
steps: [
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
},
|
2021-09-14 03:49:58 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-04-20 03:31:07 +03:00
|
|
|
test('should report before hooks step error', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test.beforeEach(async ({}) => {
|
|
|
|
throw new Error('oh my');
|
|
|
|
});
|
|
|
|
test('pass', async ({}) => {
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2023-04-20 03:31:07 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-04-20 03:31:07 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'beforeEach hook',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-04-20 03:31:07 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-04-20 03:31:07 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-04-20 03:31:07 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-09-17 01:51:27 +03:00
|
|
|
test('should not report nested after hooks', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2021-09-17 01:51:27 +03:00
|
|
|
test('timeout', async ({ page }) => {
|
|
|
|
await test.step('my step', async () => {
|
|
|
|
await new Promise(() => {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1, timeout: 2000 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2021-09-17 01:51:27 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
steps: [
|
2023-04-28 18:57:43 +03:00
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserType.launch',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newContext',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
2021-09-17 01:51:27 +03:00
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserContext.newPage',
|
|
|
|
},
|
|
|
|
]
|
2021-09-17 01:51:27 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'my step',
|
2021-10-19 07:06:18 +03:00
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
2021-09-17 01:51:27 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
steps: [
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
},
|
2021-09-17 01:51:27 +03:00
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
2023-05-01 23:53:15 +03:00
|
|
|
},
|
2021-09-17 01:51:27 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-09-14 03:49:58 +03:00
|
|
|
test('should report test.step from fixtures', async ({ runInlineTest }) => {
|
|
|
|
const expectReporterJS = `
|
|
|
|
class Reporter {
|
|
|
|
onStepBegin(test, result, step) {
|
|
|
|
console.log('%% begin ' + step.title);
|
|
|
|
}
|
|
|
|
onStepEnd(test, result, step) {
|
|
|
|
console.log('%% end ' + step.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Reporter;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': expectReporterJS,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test as base, expect } from '@playwright/test';
|
|
|
|
const test = base.extend({
|
2021-09-14 03:49:58 +03:00
|
|
|
foo: async ({}, use) => {
|
2023-02-15 06:20:56 +03:00
|
|
|
await base.step('setup foo', () => {});
|
2021-09-14 03:49:58 +03:00
|
|
|
await use(async () => {
|
|
|
|
await test.step('inside foo', () => {});
|
|
|
|
});
|
|
|
|
await test.step('teardown foo', () => {});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
test('pass', async ({ foo }) => {
|
|
|
|
await test.step('test step', async () => {
|
|
|
|
await foo();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
2023-02-08 02:11:44 +03:00
|
|
|
expect(result.outputLines).toEqual([
|
|
|
|
`begin Before Hooks`,
|
2023-05-06 20:25:32 +03:00
|
|
|
`begin fixture: foo`,
|
2023-02-08 02:11:44 +03:00
|
|
|
`begin setup foo`,
|
|
|
|
`end setup foo`,
|
2023-05-06 20:25:32 +03:00
|
|
|
`end fixture: foo`,
|
2023-02-08 02:11:44 +03:00
|
|
|
`end Before Hooks`,
|
|
|
|
`begin test step`,
|
|
|
|
`begin inside foo`,
|
|
|
|
`end inside foo`,
|
|
|
|
`end test step`,
|
|
|
|
`begin After Hooks`,
|
2023-05-06 20:25:32 +03:00
|
|
|
`begin fixture: foo`,
|
2023-02-08 02:11:44 +03:00
|
|
|
`begin teardown foo`,
|
|
|
|
`end teardown foo`,
|
2023-05-06 20:25:32 +03:00
|
|
|
`end fixture: foo`,
|
2023-02-08 02:11:44 +03:00
|
|
|
`end After Hooks`,
|
2021-09-14 03:49:58 +03:00
|
|
|
]);
|
|
|
|
});
|
2021-10-19 07:06:18 +03:00
|
|
|
|
|
|
|
test('should report expect step locations', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2021-10-19 07:06:18 +03:00
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
expect(true).toBeTruthy();
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2021-10-19 07:06:18 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
steps: [
|
2023-04-28 18:57:43 +03:00
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserType.launch',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newContext',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
2021-10-19 07:06:18 +03:00
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserContext.newPage',
|
|
|
|
},
|
|
|
|
]
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
title: 'expect.toBeTruthy',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2021-10-19 07:06:18 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
steps: [
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
},
|
2021-10-19 07:06:18 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2022-04-06 03:47:35 +03:00
|
|
|
|
|
|
|
test('should report custom expect steps', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
2023-05-16 05:37:12 +03:00
|
|
|
reporter: [['./reporter'], ['line']],
|
2022-04-06 03:47:35 +03:00
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
expect.extend({
|
|
|
|
toBeWithinRange(received, floor, ceiling) {
|
|
|
|
const pass = received >= floor && received <= ceiling;
|
|
|
|
if (pass) {
|
|
|
|
return {
|
|
|
|
message: () =>
|
|
|
|
"expected " + received + " not to be within range " + floor + " - " + ceiling,
|
|
|
|
pass: true,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
message: () =>
|
|
|
|
"expected " + received + " to be within range " + floor + " - " + ceiling,
|
|
|
|
pass: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2023-05-16 05:37:12 +03:00
|
|
|
|
|
|
|
async toBeFailingAsync(received) {
|
|
|
|
await new Promise(f => setTimeout(f, 0));
|
|
|
|
return {
|
|
|
|
message: () => "It fails!",
|
|
|
|
pass: false,
|
|
|
|
};
|
|
|
|
},
|
2022-04-06 03:47:35 +03:00
|
|
|
});
|
|
|
|
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2023-05-16 05:37:12 +03:00
|
|
|
test('fail', async ({}) => {
|
2022-04-06 03:47:35 +03:00
|
|
|
expect(15).toBeWithinRange(10, 20);
|
2023-05-16 05:37:12 +03:00
|
|
|
await expect(1).toBeFailingAsync(22);
|
2022-04-06 03:47:35 +03:00
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
2023-05-16 05:37:12 +03:00
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
expect(result.output).toContain('It fails!');
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2022-04-06 03:47:35 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2022-04-06 03:47:35 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2022-04-06 03:47:35 +03:00
|
|
|
},
|
|
|
|
title: 'expect.toBeWithinRange',
|
|
|
|
},
|
2023-05-16 05:37:12 +03:00
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-16 05:37:12 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-16 05:37:12 +03:00
|
|
|
},
|
|
|
|
title: 'expect.toBeFailingAsync',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-05-16 05:37:12 +03:00
|
|
|
},
|
2022-04-06 03:47:35 +03:00
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2022-07-30 01:16:07 +03:00
|
|
|
|
2023-04-20 03:31:07 +03:00
|
|
|
test('should not pass arguments and return value from step', async ({ runInlineTest }) => {
|
2022-07-30 01:16:07 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2022-07-30 01:16:07 +03:00
|
|
|
test('steps with return values', async ({ page }) => {
|
2023-04-20 03:31:07 +03:00
|
|
|
const v1 = await test.step('my step', (...args) => {
|
|
|
|
expect(args.length).toBe(0);
|
2022-07-30 01:16:07 +03:00
|
|
|
return 10;
|
|
|
|
});
|
|
|
|
console.log('v1 = ' + v1);
|
2023-04-20 03:31:07 +03:00
|
|
|
const v2 = await test.step('my step', async (...args) => {
|
|
|
|
expect(args.length).toBe(0);
|
2022-07-30 01:16:07 +03:00
|
|
|
return new Promise(f => setTimeout(() => f(v1 + 10), 100));
|
|
|
|
});
|
|
|
|
console.log('v2 = ' + v2);
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.output).toContain('v1 = 10');
|
|
|
|
expect(result.output).toContain('v2 = 20');
|
|
|
|
});
|
2023-01-10 03:17:06 +03:00
|
|
|
|
|
|
|
test('should mark step as failed when soft expect fails', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
2023-02-15 06:20:56 +03:00
|
|
|
import { test, expect } from '@playwright/test';
|
2023-01-10 03:17:06 +03:00
|
|
|
test('pass', async ({}) => {
|
|
|
|
await test.step('outer', async () => {
|
|
|
|
await test.step('inner', async () => {
|
|
|
|
expect.soft(1).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
await test.step('passing', () => {});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2023-01-10 03:17:06 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{ title: 'Before Hooks', category: 'hook' },
|
|
|
|
{
|
|
|
|
title: 'outer',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-01-10 03:17:06 +03:00
|
|
|
steps: [{
|
|
|
|
title: 'inner',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-01-10 03:17:06 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'expect.soft.toBe',
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
|
|
|
error: expect.any(String)
|
2023-01-10 03:17:06 +03:00
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-01-10 03:17:06 +03:00
|
|
|
}],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-01-10 03:17:06 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'passing',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-01-10 03:17:06 +03:00
|
|
|
},
|
|
|
|
{ title: 'After Hooks', category: 'hook' }
|
|
|
|
]);
|
|
|
|
});
|
2023-03-31 07:05:07 +03:00
|
|
|
|
|
|
|
test('should nest steps based on zones', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
await test.step('in beforeAll', () => {});
|
|
|
|
});
|
2023-04-20 03:31:07 +03:00
|
|
|
|
2023-03-31 07:05:07 +03:00
|
|
|
test.afterAll(async () => {
|
|
|
|
await test.step('in afterAll', () => {});
|
|
|
|
});
|
2023-04-20 03:31:07 +03:00
|
|
|
|
2023-03-31 07:05:07 +03:00
|
|
|
test.beforeEach(async () => {
|
|
|
|
await test.step('in beforeEach', () => {});
|
|
|
|
});
|
2023-04-20 03:31:07 +03:00
|
|
|
|
2023-03-31 07:05:07 +03:00
|
|
|
test.afterEach(async () => {
|
|
|
|
await test.step('in afterEach', () => {});
|
|
|
|
});
|
2023-04-20 03:31:07 +03:00
|
|
|
|
2023-03-31 07:05:07 +03:00
|
|
|
test.only('foo', async ({ page }) => {
|
|
|
|
await test.step('grand', async () => {
|
|
|
|
await Promise.all([
|
|
|
|
test.step('parent1', async () => {
|
|
|
|
await test.step('child1', async () => {
|
|
|
|
await page.click('body');
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
test.step('parent2', async () => {
|
|
|
|
await test.step('child2', async () => {
|
|
|
|
await expect(page.locator('body')).toBeVisible();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
});
|
2023-04-20 03:31:07 +03:00
|
|
|
});
|
2023-03-31 07:05:07 +03:00
|
|
|
`
|
|
|
|
}, { reporter: '', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
title: 'Before Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'beforeAll hook',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'in beforeAll',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'beforeEach hook',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'in beforeEach',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
},
|
2023-04-28 18:57:43 +03:00
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserType.launch',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newContext',
|
|
|
|
},
|
|
|
|
]
|
2023-04-28 18:57:43 +03:00
|
|
|
},
|
2023-03-31 07:05:07 +03:00
|
|
|
{
|
2023-05-06 20:25:32 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserContext.newPage',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
2023-03-31 07:05:07 +03:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'grand',
|
|
|
|
category: 'test.step',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'parent1',
|
|
|
|
category: 'test.step',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'child1',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-03-31 07:05:07 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'page.click(body)',
|
|
|
|
category: 'pw:api',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
location: {
|
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
|
|
|
column: expect.any(Number)
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'parent2',
|
|
|
|
category: 'test.step',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'child2',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-03-31 07:05:07 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'expect.toBeVisible',
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
],
|
|
|
|
location: {
|
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
|
|
|
column: expect.any(Number)
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'After Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'afterEach hook',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'in afterEach',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
},
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
},
|
2023-03-31 07:05:07 +03:00
|
|
|
{
|
|
|
|
title: 'afterAll hook',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'in afterAll',
|
|
|
|
category: 'test.step',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
}
|
|
|
|
],
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) }
|
2023-03-31 07:05:07 +03:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
2023-05-03 04:50:00 +03:00
|
|
|
|
|
|
|
test('should not mark page.close as failed when page.click fails', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = {
|
|
|
|
reporter: './reporter',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
let page: Page;
|
|
|
|
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
|
|
page = await browser.newPage();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
await page.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('fails', async () => {
|
|
|
|
test.setTimeout(2000);
|
|
|
|
await page.setContent('hello');
|
|
|
|
await page.click('div');
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
2023-05-04 02:04:20 +03:00
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
2023-05-03 04:50:00 +03:00
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'beforeAll hook',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
steps: [
|
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{ title: 'browserType.launch', category: 'pw:api' },
|
|
|
|
]
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newPage',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'page.setContent',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'page.click(div)',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'afterAll hook',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'page.close',
|
|
|
|
location: {
|
2023-09-29 19:44:00 +03:00
|
|
|
column: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
file: 'a.test.ts',
|
2023-09-29 19:44:00 +03:00
|
|
|
line: expect.any(Number),
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2023-05-13 05:15:31 +03:00
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
2023-05-03 04:50:00 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2023-05-04 02:04:20 +03:00
|
|
|
|
2023-06-01 23:22:08 +03:00
|
|
|
test('should nest page.continue inside page.goto steps', async ({ runInlineTest }) => {
|
2023-05-04 02:04:20 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
await page.route('**/*', route => route.fulfill('<html></html>'));
|
|
|
|
await page.goto('http://localhost:1234');
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
title: 'Before Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
2023-05-13 05:15:31 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: browser',
|
|
|
|
steps: [
|
|
|
|
{ title: 'browserType.launch', category: 'pw:api' },
|
|
|
|
]
|
|
|
|
},
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browser.newContext',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'pw:api',
|
|
|
|
title: 'browserContext.newPage',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
2023-05-04 02:04:20 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'page.route',
|
|
|
|
category: 'pw:api',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-05-04 02:04:20 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'page.goto(http://localhost:1234)',
|
|
|
|
category: 'pw:api',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-05-04 02:04:20 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: 'route.fulfill',
|
|
|
|
category: 'pw:api',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-05-04 02:04:20 +03:00
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'After Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
steps: [
|
2023-05-06 20:25:32 +03:00
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'fixture',
|
|
|
|
title: 'fixture: context',
|
|
|
|
},
|
2023-05-04 02:04:20 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2023-06-01 23:22:08 +03:00
|
|
|
|
|
|
|
test('should not propagate errors from within toPass', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('pass', async () => {
|
|
|
|
let i = 0;
|
|
|
|
await expect(() => {
|
|
|
|
expect(i++).toBe(2);
|
|
|
|
}).toPass();
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
title: 'Before Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'expect.toPass',
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
title: 'expect.toBe',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
title: 'expect.toBe',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
title: 'expect.toBe',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'After Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should show final toPass error', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('fail', async () => {
|
|
|
|
await expect(() => {
|
|
|
|
expect(true).toBe(false);
|
|
|
|
}).toPass({ timeout: 1 });
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
title: 'Before Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'expect.toPass',
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { file: 'a.test.ts', line: expect.any(Number), column: expect.any(Number) },
|
2023-06-01 23:22:08 +03:00
|
|
|
title: 'expect.toBe',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'After Hooks',
|
|
|
|
category: 'hook',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2023-07-06 01:30:53 +03:00
|
|
|
|
|
|
|
test('should propagate nested soft errors', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('fail', async () => {
|
|
|
|
await test.step('first outer', async () => {
|
|
|
|
await test.step('first inner', async () => {
|
|
|
|
expect.soft(1).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('second outer', async () => {
|
|
|
|
await test.step('second inner', async () => {
|
|
|
|
expect(1).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'first outer',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'first inner',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
title: 'expect.soft.toBe',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'second outer',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'second inner',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
title: 'expect.toBe',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not propagate nested hard errors', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('fail', async () => {
|
|
|
|
await test.step('first outer', async () => {
|
|
|
|
await test.step('first inner', async () => {
|
|
|
|
try {
|
|
|
|
expect(1).toBe(2);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('second outer', async () => {
|
|
|
|
await test.step('second inner', async () => {
|
|
|
|
expect(1).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'first outer',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'first inner',
|
2023-09-29 19:44:00 +03:00
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
title: 'expect.toBe',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'second outer',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
title: 'second inner',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
title: 'expect.toBe',
|
2023-09-29 19:44:00 +03:00
|
|
|
error: expect.any(String),
|
|
|
|
location: { column: expect.any(Number), file: 'a.test.ts', line: expect.any(Number) },
|
2023-07-06 01:30:53 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2023-09-29 19:44:00 +03:00
|
|
|
|
|
|
|
test('should step w/o box', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts':
|
|
|
|
` /*1*/ import { test, expect } from '@playwright/test';
|
|
|
|
/*2*/ test('fail', async () => {
|
|
|
|
/*3*/ await test.step('boxed step', async () => {
|
|
|
|
/*4*/ expect(1).toBe(2);
|
|
|
|
/*5*/ });
|
|
|
|
/*6*/ });
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
error: expect.stringContaining('a.test.ts:4:27'),
|
|
|
|
location: {
|
|
|
|
column: 26,
|
|
|
|
file: 'a.test.ts',
|
|
|
|
line: 3,
|
|
|
|
},
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
category: 'expect',
|
|
|
|
error: expect.stringContaining('a.test.ts:4:27'),
|
|
|
|
location: {
|
|
|
|
column: 27,
|
|
|
|
file: 'a.test.ts',
|
|
|
|
line: 4,
|
|
|
|
},
|
|
|
|
title: 'expect.toBe',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
title: 'boxed step',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should step w/ box', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'reporter.ts': stepHierarchyReporter,
|
|
|
|
'playwright.config.ts': `module.exports = { reporter: './reporter', };`,
|
|
|
|
'a.test.ts':
|
|
|
|
` /*1*/ import { test, expect } from '@playwright/test';
|
|
|
|
/*2*/ test('fail', async () => {
|
|
|
|
/*3*/ const helper = async () => {
|
|
|
|
/*4*/ await test.step('boxed step', async () => {
|
|
|
|
/*5*/ await expect(page.locator('body')).toHaveText('Good page', { timeout: 1 });
|
|
|
|
/*6*/ }, { box: 'self' });
|
|
|
|
/*7*/ };
|
|
|
|
/*8*/ await helper();
|
|
|
|
/*9*/ });
|
|
|
|
`
|
|
|
|
}, { reporter: '' });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
|
|
|
expect(objects).toEqual([
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'Before Hooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'test.step',
|
|
|
|
error: expect.not.stringMatching(/a.test.ts:[^8]/),
|
|
|
|
location: {
|
|
|
|
column: 21,
|
|
|
|
file: 'a.test.ts',
|
|
|
|
line: 8,
|
|
|
|
},
|
|
|
|
title: 'boxed step',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 'hook',
|
|
|
|
title: 'After Hooks',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|