Skip to content

Commit 2fc8846

Browse files
committed
Select test expectation based on browser version
1 parent 931f1a3 commit 2fc8846

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

tests/config/browserEnv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
252252
return {
253253
...result,
254254
browser: this._browser,
255+
browserVersion: this._browserVersion,
255256
contextOptions: this._contextOptions as BrowserContextOptions,
256257
contextFactory,
257258
};

tests/config/browserTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export { expect } from 'folio';
2222

2323
export type BrowserTestArgs = PlaywrightTestArgs & {
2424
browser: Browser;
25+
browserVersion: string;
2526
contextOptions: BrowserContextOptions;
2627
contextFactory: (options?: BrowserContextOptions) => Promise<BrowserContext>;
2728
};

tests/config/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ export function expectedSSLError(browserName: string): string {
5858
}
5959
return expectedSSLError;
6060
}
61+
62+
export function chromiumVersionLessThan(a: string, b: string) {
63+
const left: number[] = a.split('.').map(e => Number(e));
64+
const right: number[] = b.split('.').map(e => Number(e));
65+
for (let i = 0; i < 4; i++) {
66+
if (left[i] > right[i])
67+
return false;
68+
if (left[i] < right[i])
69+
return true;
70+
}
71+
return false;
72+
}

tests/download.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { test as it, expect } from './config/browserTest';
1818
import fs from 'fs';
1919
import path from 'path';
2020
import util from 'util';
21+
import { chromiumVersionLessThan } from './config/utils';
2122

2223
it.describe('download event', () => {
2324
it.beforeEach(async ({server}) => {
@@ -360,7 +361,7 @@ it.describe('download event', () => {
360361
expect(fs.existsSync(path.join(path1, '..'))).toBeFalsy();
361362
});
362363

363-
it('should close the context without awaiting the failed download', async ({browser, server, httpsServer, browserName}, testInfo) => {
364+
it('should close the context without awaiting the failed download', async ({browser, server, httpsServer, browserName, browserVersion}, testInfo) => {
364365
it.skip(browserName !== 'chromium', 'Only Chromium downloads on alt-click');
365366

366367
const page = await browser.newPage({ acceptDownloads: true });
@@ -378,7 +379,10 @@ it.describe('download event', () => {
378379
page.context().close(),
379380
]);
380381
expect(downloadPath).toBe(null);
381-
expect(saveError.message).toContain('File not found on disk. Check download.failure() for details.');
382+
if (chromiumVersionLessThan(browserVersion, '91.0.4472.0'))
383+
expect(saveError.message).toContain('File deleted upon browser context closure.');
384+
else
385+
expect(saveError.message).toContain('File not found on disk. Check download.failure() for details.');
382386
});
383387

384388
it('should close the context without awaiting the download', async ({browser, server, browserName, platform}, testInfo) => {

0 commit comments

Comments
 (0)