From 05edb56430204d6b622a668f7ba6f366a989251d Mon Sep 17 00:00:00 2001 From: Vitaliy Potapov Date: Sat, 23 Mar 2024 18:26:56 +0400 Subject: [PATCH] test: fix timoeut in step for pw 1.39 --- test/reporter-cucumber-html/check-report/helpers.ts | 2 +- .../check-report/timeout.test.ts | 12 ++++++++++-- test/reporter-cucumber-html/features/fixtures.ts | 2 +- test/reporter-cucumber-html/test.mjs | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/reporter-cucumber-html/check-report/helpers.ts b/test/reporter-cucumber-html/check-report/helpers.ts index 058170fb..cb4ebb33 100644 --- a/test/reporter-cucumber-html/check-report/helpers.ts +++ b/test/reporter-cucumber-html/check-report/helpers.ts @@ -79,7 +79,7 @@ export class Scenario { } getError() { - return this.getSteps().locator('div > pre'); + return this.getSteps().locator('div > pre').first(); } getTags() { diff --git a/test/reporter-cucumber-html/check-report/timeout.test.ts b/test/reporter-cucumber-html/check-report/timeout.test.ts index 2f8acd55..a77609cd 100644 --- a/test/reporter-cucumber-html/check-report/timeout.test.ts +++ b/test/reporter-cucumber-html/check-report/timeout.test.ts @@ -1,5 +1,8 @@ import { test, expect } from '@playwright/test'; import { getScenario, openReport } from './helpers'; +import { getPackageVersion } from '../../../src/utils'; + +const pwVersion = getPackageVersion('@playwright/test'); test.beforeEach(async ({ page }) => { await openReport(page); @@ -16,7 +19,10 @@ test('Scenario: timeout in before fixture', async ({ page }) => { ]); // screenshot position changes between PW versions, so check it separately await expect(scenario.getSteps()).toContainText(['screenshot']); - await expect(scenario.getSteps('failed')).toHaveCount(1); + // sometimes error is the following: + // "browser.newContext: Target page, context or browser has been closed" + // in that case there are two errors in test report. + expect(await scenario.getSteps('failed').count()).toBeGreaterThan(0); await expect(scenario.getSteps('skipped')).toHaveCount(3); await expect(scenario.getError()).toContainText( // here can be two different error messages @@ -37,7 +43,9 @@ test('Scenario: timeout in step', async ({ page }) => { await expect(scenario.getSteps('failed')).toHaveCount(1); await expect(scenario.getSteps('skipped')).toHaveCount(1); await expect(scenario.getError()).toContainText(/Test timeout of \d+ms exceeded/); - await expect(scenario.getError()).toContainText('page.waitForTimeout'); + if (!pwVersion.startsWith('1.39.')) { + await expect(scenario.getError()).toContainText('page.waitForTimeout'); + } }); test('Scenario: timeout in after fixture', async ({ page }) => { diff --git a/test/reporter-cucumber-html/features/fixtures.ts b/test/reporter-cucumber-html/features/fixtures.ts index 531915ce..f59d366b 100644 --- a/test/reporter-cucumber-html/features/fixtures.ts +++ b/test/reporter-cucumber-html/features/fixtures.ts @@ -45,7 +45,7 @@ export const test = base.extend<{ setTestTimeout: [ async ({}, use, testInfo) => { if (testInfo.title.includes('timeout')) { - testInfo.setTimeout(500); + testInfo.setTimeout(600); } await use(); }, diff --git a/test/reporter-cucumber-html/test.mjs b/test/reporter-cucumber-html/test.mjs index 3bd8267d..1476816a 100644 --- a/test/reporter-cucumber-html/test.mjs +++ b/test/reporter-cucumber-html/test.mjs @@ -5,6 +5,7 @@ const testDir = new TestDir(import.meta); test(testDir.name, () => { testDir.clearDir('reports'); + testDir.clearDir('test-results'); execPlaywrightTestWithError(testDir.name); checkHtmlReport(); });