Skip to content

Commit

Permalink
test: add timeout in step feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 11, 2024
1 parent e01d297 commit 0ec334e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 62 deletions.
118 changes: 62 additions & 56 deletions test/reporter-cucumber-html/check-report/specs/failing-step.test.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
import { expect } from '@playwright/test';
import { test } from '../fixtures';

test.use({ featureUri: 'failing-step/error.feature' });
test.describe('error', () => {
test.use({ featureUri: 'failing-step/error.feature' });

test('error in step', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Givenstep with page', // prettier-ignore
'Givenfailing step',
'WhenAction 1',
'screenshotDownload trace',
]);
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('error in step', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Givenstep with page', // prettier-ignore
'Givenfailing step',
'WhenAction 1',
'screenshotDownload trace',
]);
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([
'Givenstep with page', // prettier-ignore
'Giventimeouted step',
'WhenAction 1',
'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
await expect(scenario.getErrors()).toContainText([/Test timeout of \d+ms exceeded/]);
});
test('failing match snapshot', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Whenstep with page',
'Thenerror in match snapshot',
]);
await expect(scenario.getAttachments()).toHaveText([
'error-in-step-failing-match-snapshot-1-expected.txtbla-bla',
'error-in-step-failing-match-snapshot-1-actual.txtExample Domain',
'screenshot',
]);
await expect(scenario.getSteps('passed')).toHaveCount(1);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(0);
await expect(scenario.getErrors()).toContainText(['toMatchSnapshot']);
});

test('failing match snapshot', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Whenstep with page',
'Thenerror in match snapshot',
]);
await expect(scenario.getAttachments()).toHaveText([
'error-in-step-failing-match-snapshot-1-expected.txtbla-bla',
'error-in-step-failing-match-snapshot-1-actual.txtExample Domain',
'screenshot',
]);
await expect(scenario.getSteps('passed')).toHaveCount(1);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(0);
await expect(scenario.getErrors()).toContainText(['toMatchSnapshot']);
test('soft assertions', async ({ scenario }) => {
await expect(scenario.getSteps()).toHaveText([
/Givenfailing soft assertion "foo"/,
'AndAction 1',
/Andfailing soft assertion "bar"/,
'AndAction 2',
// not 'screenshot', b/c no page
// 'screenshot',
'Download trace',
]);
await expect(scenario.getSteps('passed')).toHaveCount(2);
await expect(scenario.getSteps('failed')).toHaveCount(2);
await expect(scenario.getSteps('skipped')).toHaveCount(0);
await expect(scenario.getErrors()).toContainText([
'Expected: "foo" Received: "xxx"',
'Expected: "bar" Received: "xxx"',
]);
});
});

test('soft assertions', async ({ scenario }) => {
await expect(scenario.getSteps()).toHaveText([
/Givenfailing soft assertion "foo"/,
'AndAction 1',
/Andfailing soft assertion "bar"/,
'AndAction 2',
// not 'screenshot', b/c no page
// 'screenshot',
'Download trace',
]);
await expect(scenario.getSteps('passed')).toHaveCount(2);
await expect(scenario.getSteps('failed')).toHaveCount(2);
await expect(scenario.getSteps('skipped')).toHaveCount(0);
await expect(scenario.getErrors()).toContainText([
'Expected: "foo" Received: "xxx"',
'Expected: "bar" Received: "xxx"',
]);
test.describe('timeout', () => {
test.use({ featureUri: 'failing-step/timeout.feature' });

test('timeout in step', async ({ scenario }) => {
await expect(scenario.getSteps()).toContainText([
'Givenstep with page', // prettier-ignore
'Giventimeouted step',
'WhenAction 1',
'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
await expect(scenario.getErrors()).toContainText([/Test timeout of \d+ms exceeded/]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ Feature: error-in-step
Given failing step
When Action 1

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

# - If this scenario name changed, snapshot file names should also change
Scenario: failing match snapshot
When step with page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: timeout-in-step

Scenario: timeout in step
Given step with page
Given timeouted step
When Action 1
4 changes: 3 additions & 1 deletion test/reporter-cucumber-html/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Generate Cucumber HTML reporter and check the report via Playwright.
* To check particular scenario:
* 1. add @only tag to the scenario
* 2. add `test.only` to the related spec file in check-report directory
* 2. comment checkHtmlReport() call in this file
* OR
* add `test.only` to the related spec file in check-report directory
*/
import {
test,
Expand Down

0 comments on commit 0ec334e

Please sign in to comment.