From 0ec334e8bc1fb3092a0608d28493d6b8a0d74f90 Mon Sep 17 00:00:00 2001 From: vitalets Date: Wed, 11 Dec 2024 18:39:23 +0400 Subject: [PATCH] test: add timeout in step feature --- .../check-report/specs/failing-step.test.ts | 118 +++++++++--------- .../features/failing-step/error.feature | 5 - .../features/failing-step/timeout.feature | 6 + test/reporter-cucumber-html/test.mjs | 4 +- 4 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 test/reporter-cucumber-html/features/failing-step/timeout.feature diff --git a/test/reporter-cucumber-html/check-report/specs/failing-step.test.ts b/test/reporter-cucumber-html/check-report/specs/failing-step.test.ts index 426b9b10..fc438f01 100644 --- a/test/reporter-cucumber-html/check-report/specs/failing-step.test.ts +++ b/test/reporter-cucumber-html/check-report/specs/failing-step.test.ts @@ -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/]); + }); }); diff --git a/test/reporter-cucumber-html/features/failing-step/error.feature b/test/reporter-cucumber-html/features/failing-step/error.feature index 3f5427f6..5cbe9cdf 100644 --- a/test/reporter-cucumber-html/features/failing-step/error.feature +++ b/test/reporter-cucumber-html/features/failing-step/error.feature @@ -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 diff --git a/test/reporter-cucumber-html/features/failing-step/timeout.feature b/test/reporter-cucumber-html/features/failing-step/timeout.feature new file mode 100644 index 00000000..450aa47d --- /dev/null +++ b/test/reporter-cucumber-html/features/failing-step/timeout.feature @@ -0,0 +1,6 @@ +Feature: timeout-in-step + + Scenario: timeout in step + Given step with page + Given timeouted step + When Action 1 diff --git a/test/reporter-cucumber-html/test.mjs b/test/reporter-cucumber-html/test.mjs index b8324b9b..efcb041c 100644 --- a/test/reporter-cucumber-html/test.mjs +++ b/test/reporter-cucumber-html/test.mjs @@ -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,