Skip to content

Commit

Permalink
test: brush up fixtures, unflake some tests (#32854)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Sep 27, 2024
1 parent a395fb2 commit 5947c21
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 94 deletions.
12 changes: 5 additions & 7 deletions tests/config/browserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,23 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
await run(false);
}, { scope: 'worker' }],

defaultSameSiteCookieValue: [async ({ browserName, platform }, run) => {
defaultSameSiteCookieValue: [async ({ browserName, platform, macVersion }, run) => {
if (browserName === 'chromium' || browserName as any === '_bidiChromium')
await run('Lax');
else if (browserName === 'webkit' && platform === 'linux')
await run('Lax');
else if (browserName === 'webkit' && platform === 'darwin' && parseInt(os.release(), 10) >= 24)
// macOS 15 Sequoia onwards
else if (browserName === 'webkit' && platform === 'darwin' && macVersion >= 15)
await run('Lax');
else if (browserName === 'webkit')
// Windows + older macOS
await run('None');
await run('None'); // Windows + older macOS
else if (browserName === 'firefox' || browserName as any === '_bidiFirefox')
await run('None');
else
throw new Error('unknown browser - ' + browserName);
}, { scope: 'worker' }],

sameSiteStoredValueForNone: [async ({ browserName, isMac }, run) => {
if (browserName === 'webkit' && isMac && parseInt(os.release(), 10) >= 24)
sameSiteStoredValueForNone: [async ({ browserName, isMac, macVersion }, run) => {
if (browserName === 'webkit' && isMac && macVersion >= 15)
await run('Lax');
else
await run('None');
Expand Down
9 changes: 9 additions & 0 deletions tests/config/platformFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/

import { test } from '@playwright/test';
import os from 'os';

export type PlatformWorkerFixtures = {
platform: 'win32' | 'darwin' | 'linux';
isWindows: boolean;
isMac: boolean;
isLinux: boolean;
macVersion: number; // major only, 11 or later, zero if not mac
};

function platform(): 'win32' | 'darwin' | 'linux' {
Expand All @@ -33,9 +35,16 @@ function platform(): 'win32' | 'darwin' | 'linux' {
return process.platform as 'win32' | 'darwin' | 'linux';
}

function macVersion() {
if (process.platform !== 'darwin')
return 0;
return +os.release().split('.')[0] - 9;
}

export const platformTest = test.extend<{}, PlatformWorkerFixtures>({
platform: [platform(), { scope: 'worker' }],
isWindows: [platform() === 'win32', { scope: 'worker' }],
isMac: [platform() === 'darwin', { scope: 'worker' }],
isLinux: [platform() === 'linux', { scope: 'worker' }],
macVersion: [macVersion(), { scope: 'worker' }],
});
5 changes: 2 additions & 3 deletions tests/library/browsercontext-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import os from 'os';
import { contextTest as it, expect } from '../config/browserTest';

it('should return no cookies in pristine browser context', async ({ context, page, server }) => {
Expand Down Expand Up @@ -351,7 +350,7 @@ it('should be able to send third party cookies via an iframe', async ({ browser,
}
});

it('should support requestStorageAccess', async ({ page, server, channel, browserName, isMac, isLinux, isWindows }) => {
it('should support requestStorageAccess', async ({ page, server, channel, browserName, isMac, isLinux, isWindows, macVersion }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17285' });
it.skip(browserName === 'chromium', 'requestStorageAccess API is not available in Chromium');
it.skip(channel === 'firefox-beta', 'hasStorageAccess returns true, but no cookie is sent');
Expand Down Expand Up @@ -397,7 +396,7 @@ it('should support requestStorageAccess', async ({ page, server, channel, browse
server.waitForRequest('/title.html'),
frame.evaluate(() => fetch('/title.html'))
]);
if ((isLinux || (isMac && parseInt(os.release(), 10) >= 24)) && browserName === 'webkit')
if ((isLinux || (isMac && macVersion >= 15)) && browserName === 'webkit')
expect(serverRequest.headers.cookie).toBe(undefined);
else
expect(serverRequest.headers.cookie).toBe('name=value');
Expand Down
5 changes: 2 additions & 3 deletions tests/library/browsercontext-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { devices } from '@playwright/test';
import { contextTest as it, expect } from '../config/browserTest';
import { browserTest } from '../config/browserTest';
import { verifyViewport } from '../config/utils';
import * as os from 'os';

it('should get the proper default viewport size', async ({ page, server }) => {
await verifyViewport(page, 1280, 720);
Expand Down Expand Up @@ -176,10 +175,10 @@ browserTest('should be able to get correct orientation angle on non-mobile devic
await context.close();
});

it('should set window.screen.orientation.type for mobile devices', async ({ contextFactory, browserName, server, isMac }) => {
it('should set window.screen.orientation.type for mobile devices', async ({ contextFactory, browserName, server, isMac, macVersion }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31151' });
it.skip(browserName === 'firefox', 'Firefox does not support mobile emulation');
it.skip(browserName === 'webkit' && isMac && parseInt(os.release().split('.')[0], 10) <= 21, 'WebKit on macOS 12 is frozen and does not support orientation.type override');
it.skip(browserName === 'webkit' && isMac && macVersion <= 12, 'WebKit on macOS 12 is frozen and does not support orientation.type override');
const context = await contextFactory(devices['iPhone 14']);
const page = await context.newPage();
await page.goto(server.PREFIX + '/index.html');
Expand Down
5 changes: 2 additions & 3 deletions tests/library/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import fs from 'fs';
import os from 'os';
import type http from 'http';
import type net from 'net';
import * as path from 'path';
Expand Down Expand Up @@ -678,9 +677,9 @@ for (const kind of ['launchServer', 'run-server'] as const) {
expect(await response.json()).toEqual({ 'foo': 'bar' });
});

test('should upload large file', async ({ connect, startRemoteServer, server, browserName, isMac, mode }, testInfo) => {
test('should upload large file', async ({ connect, startRemoteServer, server, browserName, isMac, macVersion, mode }, testInfo) => {
test.skip(mode.startsWith('service'), 'Take it easy on service');
test.skip(browserName === 'webkit' && isMac && parseInt(os.release(), 10) < 20, 'WebKit for macOS 10.15 is frozen and does not have corresponding protocol features.');
test.skip(browserName === 'webkit' && isMac && macVersion < 11, 'WebKit for macOS 10.15 is frozen and does not have corresponding protocol features.');
test.slow();
const remoteServer = await startRemoteServer(kind);
const browser = await connect(remoteServer.wsEndpoint());
Expand Down
18 changes: 10 additions & 8 deletions tests/library/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import url from 'url';
import { contextTest as it, expect } from '../config/browserTest';
import { hostPlatform } from '../../packages/playwright-core/src/utils/hostPlatform';

it('SharedArrayBuffer should work @smoke', async function({ contextFactory, httpsServer, isMac, browserName }) {
it.skip(browserName === 'webkit' && isMac && parseInt(os.release().split('.')[0], 10) <= 21, 'WebKit on macOS 12 is frozen and does not support SharedArrayBuffer');
it('SharedArrayBuffer should work @smoke', async function({ contextFactory, httpsServer, isMac, macVersion, browserName }) {
it.skip(browserName === 'webkit' && isMac && macVersion <= 12, 'WebKit on macOS 12 is frozen and does not support SharedArrayBuffer');
const context = await contextFactory({ ignoreHTTPSErrors: true });
const page = await context.newPage();
httpsServer.setRoute('/sharedarraybuffer', (req, res) => {
Expand Down Expand Up @@ -65,13 +65,13 @@ it('should respect CSP @smoke', async ({ page, server }) => {
expect(await page.evaluate(() => window['testStatus'])).toBe('SUCCESS');
});

it('should play video @smoke', async ({ page, asset, browserName, platform, mode }) => {
it('should play video @smoke', async ({ page, asset, browserName, platform, macVersion, mode }) => {
// TODO: the test passes on Windows locally but fails on GitHub Action bot,
// apparently due to a Media Pack issue in the Windows Server.
// Also the test is very flaky on Linux WebKit.
it.fixme(browserName === 'webkit' && platform !== 'darwin');
it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/5721');
it.fixme(browserName === 'webkit' && platform === 'darwin' && parseInt(os.release(), 10) === 20, 'Does not work on BigSur');
it.fixme(browserName === 'webkit' && platform === 'darwin' && macVersion === 11, 'Does not work on BigSur');
it.skip(mode.startsWith('service'));

// Safari only plays mp4 so we test WebKit with an .mp4 clip.
Expand All @@ -84,8 +84,8 @@ it('should play video @smoke', async ({ page, asset, browserName, platform, mode
await page.$eval('video', v => v.pause());
});

it('should play webm video @smoke', async ({ page, asset, browserName, platform, mode }) => {
it.fixme(browserName === 'webkit' && platform === 'darwin' && parseInt(os.release(), 10) === 20, 'Does not work on BigSur');
it('should play webm video @smoke', async ({ page, asset, browserName, platform, macVersion, mode }) => {
it.fixme(browserName === 'webkit' && platform === 'darwin' && macVersion === 11, 'Does not work on BigSur');
it.fixme(browserName === 'webkit' && platform === 'win32');
it.skip(mode.startsWith('service'));

Expand Down Expand Up @@ -143,6 +143,8 @@ it('should not crash on showDirectoryPicker', async ({ page, server, browserName
it.skip(browserName === 'chromium' && browserMajorVersion < 99, 'Fixed in Chromium r956769');
it.skip(browserName !== 'chromium', 'showDirectoryPicker is only available in Chromium');
await page.goto(server.EMPTY_PAGE);
// "User activation is required to show a file picker." - so we click first.
await page.locator('body').click();
page.evaluate(async () => {
const dir = await (window as any).showDirectoryPicker();
return dir.name;
Expand Down Expand Up @@ -240,9 +242,9 @@ it('make sure that XMLHttpRequest upload events are emitted correctly', async ({
expect(events).toEqual(['loadstart', 'progress', 'load', 'loadend']);
});

it('loading in HTMLImageElement.prototype', async ({ page, server, browserName, isMac }) => {
it('loading in HTMLImageElement.prototype', async ({ page, server, browserName, isMac, macVersion }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/22738' });
it.skip(browserName === 'webkit' && isMac && parseInt(os.release(), 10) < 21, 'macOS 11 is frozen');
it.skip(browserName === 'webkit' && isMac && macVersion < 12, 'macOS 11 is frozen');
await page.goto(server.EMPTY_PAGE);
const defined = await page.evaluate(() => 'loading' in HTMLImageElement.prototype);
expect(defined).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions tests/library/chromium/connect-over-cdp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ test('should connect to an existing cdp session when passed as a first argument'
}
});

test('should use proxy with connectOverCDP', async ({ browserType, server, mode }, testInfo) => {
test('should use proxy with connectOverCDP', async ({ browserType, server }, testInfo) => {
server.setRoute('/target.html', async (req, res) => {
res.end('<html><title>Served by the proxy</title></html>');
});
const port = 9339 + testInfo.workerIndex;
const browserServer = await browserType.launch({
args: ['--remote-debugging-port=' + port, ...(process.platform === 'win32' ? ['--proxy-server=some-value'] : [])]
args: ['--remote-debugging-port=' + port]
});
try {
const cdpBrowser = await browserType.connectOverCDP(`http://127.0.0.1:${port}/`);
Expand Down
Loading

0 comments on commit 5947c21

Please sign in to comment.