Skip to content

Commit

Permalink
test: html reporter avoid example com navigations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 8, 2024
1 parent 6312d6a commit fe76721
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ test.use({ featureUri: 'error-in-bg/sample.feature' });
test('background is failing', async ({ feature }) => {
const background = feature.getBackground();
await expect(background.getSteps()).toContainText([
'failing step', // prettier-ignore
'step with page', // prettier-ignore
'failing step',
]);
await expect(background.getSteps('failed')).toHaveCount(1);
await expect(background.getErrors()).toContainText(['Timed out 1ms waiting for expect']);
await expect(background.getErrors()).toContainText(['expect(true).toBe(false)']);
});

test('scenario 1', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'GivenAction 1', // prettier-ignore
'screenshot',
'screenshotDownload trace',
]);
await expect(scenario.getSteps('skipped')).toHaveCount(1);
await expect(scenario.getErrors()).not.toBeVisible();
Expand All @@ -24,7 +25,7 @@ test('scenario 1', async ({ scenario }) => {
test('scenario 2', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'GivenAction 2', // prettier-ignore
'screenshot',
'screenshotDownload trace',
]);
await expect(scenario.getSteps('skipped')).toHaveCount(1);
await expect(scenario.getErrors()).not.toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ test.use({ featureUri: 'error-in-step/sample.feature' });

test('error in step', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Givenfailing step', // prettier-ignore
'Givenstep with page', // prettier-ignore
'Givenfailing step',
'WhenAction 1',
'screenshotDownload trace',
]);
await expect(scenario.getErrors()).toContainText([
'Timed out 1ms waiting for expect', // prettier-ignore
]);
await expect(scenario.getSteps('passed')).toHaveCount(1);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(1);
await expect(scenario.getErrors()).toContainText(['expect(true).toBe(false)']);
});

test('timeout in step', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'GivenAction 0',
'Givenstep with page', // prettier-ignore
'Giventimeouted step',
'WhenAction 1',
// not 'screenshot', b/c no page
// 'screenshot',
// 'Download trace' can be attached to 'timeouted step' (pw 1.43) - is it a bug?
'screenshot',
// don't check 'Download trace' as it is attached to 'timeouted step' in pw 1.42 / 1.43
// 'Download trace',
]);
// don't check passed/skipped steps counts b/c in different PW versions it's different
Expand All @@ -29,8 +31,8 @@ test('timeout in step', async ({ scenario }) => {

test('failing match snapshot', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Whenopen example.com',
'Thenpage title snapshot matches the golden one',
'Whenstep with page',
'Thenerror in match snapshot',
]);
await expect(scenario.getAttachments()).toHaveText([
'error-in-step-failing-match-snapshot-1-expected.txtbla-bla',
Expand All @@ -40,12 +42,7 @@ test('failing match snapshot', async ({ scenario }) => {
await expect(scenario.getSteps('passed')).toHaveCount(1);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(0);
// since pw 1.49 error text for snapshots was changed.
// before: Snapshot comparison failed
// after: expect(string).toMatchSnapshot(expected)
await expect(scenario.getErrors()).toContainText(
/Snapshot comparison failed|expect\(string\)\.toMatchSnapshot\(expected\)/,
);
await expect(scenario.getErrors()).toContainText(['toMatchSnapshot']);
});

test('soft assertions', async ({ scenario }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Feature: error-in-bg

Background:
Given step with page
Given failing step

Scenario: scenario 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
Feature: error-in-step

# - Increased timeout b/c this test opens page
@timeout:10_000
Scenario: error in step
Given step with page
Given failing step
When Action 1

Scenario: timeout in step
Given Action 0
Given step with page
Given timeouted step
When Action 1

# - If this scenario name changed, snapshot file names should also change
# - Increased timeout b/c this test opens page
@timeout:10_000
Scenario: failing match snapshot
When open example.com
Then page title snapshot matches the golden one
When step with page
Then error in match snapshot

Scenario: soft assertions
Given failing soft assertion "foo"
Expand Down
4 changes: 2 additions & 2 deletions test/reporter-cucumber-html/features/error-in-step/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ When('fails until retry {int}', async ({ $testInfo }, retry: number) => {
}
});

Then('page title snapshot matches the golden one', async ({ page }) => {
expect(await page.title()).toMatchSnapshot();
Then('error in match snapshot', async () => {
expect('Example Domain').toMatchSnapshot();
});
10 changes: 2 additions & 8 deletions test/reporter-cucumber-html/features/shared.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ const { Given, When } = createBdd();

When('Action {int}', () => {});

Given('failing step', async ({ page }) => {
// using 'page' here to have a screenshot in report
await page.goto('https://example.com');
await expect(page.getByText('missing string')).toBeVisible();
Given('failing step', async () => {
expect(true).toBe(false);
});

// using 'page' here to have a screenshot in report
When('step with page', async ({ page }) => {
return page;
});

When('open example.com', async ({ page }) => {
await page.goto('https://example.com');
});

0 comments on commit fe76721

Please sign in to comment.