Skip to content

Commit

Permalink
test: fix timoeut in step for pw 1.39
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Mar 23, 2024
1 parent 7e83fed commit 05edb56
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/reporter-cucumber-html/check-report/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Scenario {
}

getError() {
return this.getSteps().locator('div > pre');
return this.getSteps().locator('div > pre').first();
}

getTags() {
Expand Down
12 changes: 10 additions & 2 deletions test/reporter-cucumber-html/check-report/timeout.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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
Expand All @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/reporter-cucumber-html/features/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
1 change: 1 addition & 0 deletions test/reporter-cucumber-html/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const testDir = new TestDir(import.meta);

test(testDir.name, () => {
testDir.clearDir('reports');
testDir.clearDir('test-results');
execPlaywrightTestWithError(testDir.name);
checkHtmlReport();
});
Expand Down

0 comments on commit 05edb56

Please sign in to comment.