Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: move PW_CLOCK handling into test harness (#41214)

Dmitry Gozman9e45b45ee610
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index e27f1b91c2..7aa9ccc3d3 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -418,17 +418,6 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
} : {};
const context = await browser.newContext({ ...videoOptions, ...options }) as BrowserContextImpl;
- if (process.env.PW_CLOCK === 'frozen') {
- await context._wrapApiCall(async () => {
- await context.clock.install({ time: 0 });
- await context.clock.pauseAt(1000);
- }, { internal: true });
- } else if (process.env.PW_CLOCK === 'realtime') {
- await context._wrapApiCall(async () => {
- await context.clock.install({ time: 0 });
- }, { internal: true });
- }
-
let closed = false;
const close = async () => {
if (closed)
diff --git a/tests/config/browserTest.ts b/tests/config/browserTest.ts
index dce99d775f..2a5c4ba8b5 100644
--- a/tests/config/browserTest.ts
+++ b/tests/config/browserTest.ts
@@ -59,7 +59,9 @@ type BrowserTestTestFixtures = PageTestFixtures & {
autoSkipBidiTest: void;
};
-const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>({
+type ContextFactory = (options?: BrowserContextOptions) => Promise<{ context: BrowserContext, close: () => Promise<void> }>;
+
+const test = baseTest.extend<BrowserTestTestFixtures & { _contextFactory: ContextFactory }, BrowserTestWorkerFixtures>({
browserVersion: [async ({ browser }, run) => {
await run(browser.version());
}, { scope: 'worker' }],
@@ -115,7 +117,25 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
await use(browserName === 'webkit' && (hostPlatform.startsWith('debian11') || hostPlatform.startsWith('ubuntu20.04') || (isMac && macVersion < 15)));
}, { scope: 'worker' }],
- contextFactory: async ({ _contextFactory }: any, run) => {
+ _contextFactory: async ({ _contextFactory }, use) => {
+ await use(async options => {
+ const result = await _contextFactory(options);
+ const { context } = result;
+ if (process.env.PW_CLOCK === 'frozen') {
+ await (context as any)._wrapApiCall(async () => {
+ await context.clock.install({ time: 0 });
+ await context.clock.pauseAt(1000);
+ }, { internal: true });
+ } else if (process.env.PW_CLOCK === 'realtime') {
+ await (context as any)._wrapApiCall(async () => {
+ await context.clock.install({ time: 0 });
+ }, { internal: true });
+ }
+ return result;
+ });
+ },
+
+ contextFactory: async ({ _contextFactory }, run) => {
await run(async options => {
const { context } = await _contextFactory(options);
return context;
@@ -123,7 +143,6 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
},
createUserDataDir: async ({ mode }, run) => {
- test.skip(mode.startsWith('service'));
const dirs: string[] = [];
// We do not put user data dir in testOutputPath,
// because we do not want to upload them as test result artifacts.
diff --git a/tests/library/browsercontext-proxy.spec.ts b/tests/library/browsercontext-proxy.spec.ts
index 609f32b6c2..c5f25e3f5a 100644
--- a/tests/library/browsercontext-proxy.spec.ts
+++ b/tests/library/browsercontext-proxy.spec.ts
@@ -16,8 +16,6 @@
import { browserTest as it, expect } from '../config/browserTest';
-it.skip(({ mode }) => mode.startsWith('service'));
-
it.beforeEach(({ server }) => {
server.setRoute('/target.html', async (req, res) => {
res.end('<html><title>Served by the proxy</title></html>');
diff --git a/tests/library/browsercontext-webauthn.spec.ts b/tests/library/browsercontext-webauthn.spec.ts
index 61409c5a27..d180e9e93e 100644
--- a/tests/library/browsercontext-webauthn.spec.ts
+++ b/tests/library/browsercontext-webauthn.spec.ts
@@ -16,8 +16,6 @@
import { browserTest as it, expect } from '../config/browserTest';
-it.skip(({ mode }) => mode.startsWith('service'));
-
it('should not intercept navigator.credentials without install()', async ({ contextFactory, server }) => {
const context = await contextFactory();
// Seed a credential, but do not install the interceptor.
diff --git a/tests/library/browsertype-basic.spec.ts b/tests/library/browsertype-basic.spec.ts
index 39bac27969..dacd9969d8 100644
--- a/tests/library/browsertype-basic.spec.ts
+++ b/tests/library/browsertype-basic.spec.ts
@@ -20,7 +20,6 @@ import { playwrightTest as test, expect } from '../config/browserTest';
test('browserType.executablePath should work', async ({ browserType, channel, mode }) => {
test.skip(!!channel, 'We skip browser download when testing a channel');
- test.skip(mode.startsWith('service'));
test.skip(!!(browserType as any)._playwright._defaultLaunchOptions.executablePath, 'Skip with custom executable path');
const executablePath = browserType.executablePath();
diff --git a/tests/library/browsertype-launch.spec.ts b/tests/library/browsertype-launch.spec.ts
index 11f123c863..8c138782ce 100644
--- a/tests/library/browsertype-launch.spec.ts
+++ b/tests/library/browsertype-launch.spec.ts
@@ -62,8 +62,6 @@ it('should throw if page argument is passed', async ({ browserType, browserName,
});
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset, channel }) => {
- it.skip(mode.startsWith('service'));
-
const error = await browserType.launch({ executablePath: asset('dummy_bad_browser_executable.js') }).catch(e => e);
if (channel === 'webkit-wsl')
expect(error.message).toContain('Cannot specify executablePath when using the \"webkit-wsl\" channel.');
@@ -72,7 +70,6 @@ it('should reject if launched browser fails immediately', async ({ mode, browser
});
it('should reject if executable path is invalid', async ({ browserType, mode, channel }) => {
- it.skip(mode.startsWith('service'), 'on service mode we dont allow passing custom executable path');
let waitError: Error | undefined;
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
if (channel === 'webkit-wsl')
@@ -102,8 +99,6 @@ it('should handle exception and report launch log', async ({ browserType, mode }
});
it('should accept objects as options', async ({ mode, browserType }) => {
- it.skip(mode.startsWith('service'));
-
// @ts-expect-error process is not a real option.
const browser = await browserType.launch({ process });
await browser.close();
diff --git a/tests/library/capabilities.spec.ts b/tests/library/capabilities.spec.ts
index b7b2407bbc..30c0869270 100644
--- a/tests/library/capabilities.spec.ts
+++ b/tests/library/capabilities.spec.ts
@@ -68,7 +68,6 @@ it('should respect CSP @smoke', async ({ page, server }) => {
it('should play video @smoke', async ({ page, asset, browserName, isWindows, isLinux, mode }) => {
it.skip(browserName === 'webkit' && isWindows, 'passes locally but fails on GitHub Action bot, apparently due to a Media Pack issue in the Windows Server');
- it.skip(mode.startsWith('service'));
// Safari only plays mp4 so we test WebKit with an .mp4 clip.
const fileName = browserName === 'webkit' ? 'video_mp4.html' : 'video.html';
@@ -82,7 +81,6 @@ it('should play video @smoke', async ({ page, asset, browserName, isWindows, isL
it('should play webm video @smoke', async ({ page, asset, browserName, platform, macVersion, mode }) => {
it.skip(browserName === 'webkit' && platform === 'win32', 'not supported');
- it.skip(mode.startsWith('service'));
const absolutePath = asset('video_webm.html');
// Our test server doesn't support range requests required to play on Mac,
diff --git a/tests/library/debug-controller.spec.ts b/tests/library/debug-controller.spec.ts
index 232d818fcb..90f26ef4dd 100644
--- a/tests/library/debug-controller.spec.ts
+++ b/tests/library/debug-controller.spec.ts
@@ -76,7 +76,7 @@ const test = baseTest.extend<Fixtures>({
});
test.slow(true, 'All controller tests are slow');
-test.skip(({ mode }) => mode.startsWith('service') || mode === 'driver');
+test.skip(({ mode }) => mode === 'driver');
// Force a separate worker to avoid registered selector engines from other tests.
// See https://github.com/microsoft/playwright/pull/37103.
diff --git a/tests/library/download.spec.ts b/tests/library/download.spec.ts
index d64bcd05aa..cc867bf712 100644
--- a/tests/library/download.spec.ts
+++ b/tests/library/download.spec.ts
@@ -672,10 +672,6 @@ it('should save to user-specified path', async ({ browser, server, mode }, testI
page.waitForEvent('download'),
page.click('a')
]);
- if (mode.startsWith('service')) {
- const error = await download.path().catch(e => e);
- expect(error.message).toContain('Path is not available when connecting remotely. Use saveAs() to save a local copy.');
- }
const userPath = testInfo.outputPath('download.txt');
await download.saveAs(userPath);
expect(fs.existsSync(userPath)).toBeTruthy();
diff --git a/tests/library/firefox/launcher.spec.ts b/tests/library/firefox/launcher.spec.ts
index 60ac191fc3..740c9ccd97 100644
--- a/tests/library/firefox/launcher.spec.ts
+++ b/tests/library/firefox/launcher.spec.ts
@@ -20,7 +20,6 @@ import { TestServer } from '../../config/testserver';
import { inheritAndCleanEnv } from '../../config/utils';
it('should pass firefox user preferences', async ({ browserType, mode }) => {
- it.skip(mode.startsWith('service'));
const browser = await browserType.launch({
firefoxUserPrefs: {
'network.proxy.type': 1,
@@ -35,7 +34,6 @@ it('should pass firefox user preferences', async ({ browserType, mode }) => {
});
it('should pass firefox user preferences in persistent', async ({ mode, launchPersistent }) => {
- it.skip(mode.startsWith('service'));
const { page } = await launchPersistent({
firefoxUserPrefs: {
'network.proxy.type': 1,
@@ -48,8 +46,6 @@ it('should pass firefox user preferences in persistent', async ({ mode, launchPe
});
it('should support custom firefox policies', async ({ browserType, mode, asset, loopback }, testInfo) => {
- it.skip(mode.startsWith('service'));
-
const policies = {
'policies': {
'Certificates': {
diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.ts
index a1cb818b93..1360b6362b 100644
--- a/tests/library/har.spec.ts
+++ b/tests/library/har.spec.ts
@@ -619,10 +619,8 @@ it('should have connection details', async ({ contextFactory, server, browserNam
await page.goto(server.EMPTY_PAGE);
const log = await getLog();
const { serverIPAddress, _serverPort: port, _securityDetails: securityDetails } = log.entries[0];
- if (!mode.startsWith('service')) {
- expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
- expect(port).toBe(server.PORT);
- }
+ expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
+ expect(port).toBe(server.PORT);
expect(securityDetails).toEqual({});
});
@@ -634,10 +632,8 @@ it('should have security details', async ({ contextFactory, httpsServer, browser
await page.request.get(httpsServer.EMPTY_PAGE);
const log = await getLog();
const { serverIPAddress, _serverPort: port, _securityDetails: securityDetails } = log.entries[0];
- if (!mode.startsWith('service')) {
- expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
- expect(port).toBe(httpsServer.PORT);
- }
+ expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
+ expect(port).toBe(httpsServer.PORT);
if (browserName === 'webkit')
expect(securityDetails).toEqual({ protocol: 'TLS 1.3', subjectName: 'playwright-test', validFrom: 1691708270, validTo: 2007068270 });
else
@@ -658,16 +654,14 @@ it('should have connection details for redirects', async ({ contextFactory, serv
if (browserName === 'webkit') {
expect(detailsFoo.serverIPAddress).toBeUndefined();
expect(detailsFoo._serverPort).toBeUndefined();
- } else if (!mode.startsWith('service')) {
+ } else {
expect(detailsFoo.serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
expect(detailsFoo._serverPort).toBe(server.PORT);
}
- if (!mode.startsWith('service')) {
- const detailsEmpty = log.entries[1];
- expect(detailsEmpty.serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
- expect(detailsEmpty._serverPort).toBe(server.PORT);
- }
+ const detailsEmpty = log.entries[1];
+ expect(detailsEmpty.serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
+ expect(detailsEmpty._serverPort).toBe(server.PORT);
});
it('should have connection details for failed requests', async ({ contextFactory, server, browserName, platform, mode }, testInfo) => {
@@ -678,20 +672,16 @@ it('should have connection details for failed requests', async ({ contextFactory
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
await page.goto(server.PREFIX + '/one-style.html');
const log = await getLog();
- if (!mode.startsWith('service')) {
- const { serverIPAddress, _serverPort: port } = log.entries[0];
- expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
- expect(port).toBe(server.PORT);
- }
+ const { serverIPAddress, _serverPort: port } = log.entries[0];
+ expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
+ expect(port).toBe(server.PORT);
});
it('should return server address directly from response', async ({ page, server, mode }) => {
const response = await page.goto(server.EMPTY_PAGE);
- if (!mode.startsWith('service')) {
- const { ipAddress, port } = (await response!.serverAddr())!;
- expect(ipAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
- expect(port).toBe(server.PORT);
- }
+ const { ipAddress, port } = (await response!.serverAddr())!;
+ expect(ipAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
+ expect(port).toBe(server.PORT);
});
it('should return security details directly from response', async ({ contextFactory, httpsServer, browserName, platform, channel }) => {
diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.ts
index 2f261c9c99..9fa145a651 100644
--- a/tests/library/inspector/inspectorTest.ts
+++ b/tests/library/inspector/inspectorTest.ts
@@ -74,7 +74,6 @@ export const test = contextTest.extend<CLITestArgs>({
runCLI: async ({ childProcess, browserName, channel, headless, mode, launchOptions }, run, testInfo) => {
testInfo.slow();
- testInfo.skip(mode.startsWith('service'));
let cli: CLIMock | undefined;
await run(cliArgs => {
diff --git a/tests/library/launcher.spec.ts b/tests/library/launcher.spec.ts
index 8c2c37a9ef..ba29451d5c 100644
--- a/tests/library/launcher.spec.ts
+++ b/tests/library/launcher.spec.ts
@@ -44,7 +44,6 @@ it('should kill browser process on timeout after close', async ({ browserType, m
it('should throw a friendly error if its headed and there is no xserver on linux running', async ({ mode, browserType, platform, channel }) => {
it.skip(platform !== 'linux');
- it.skip(mode.startsWith('service'));
it.skip(channel === 'chromium-headless-shell', 'shell is never headed');
it.skip(channel === 'chromium-tip-of-tree-headless-shell', 'shell is never headed');
diff --git a/tests/library/proxy.spec.ts b/tests/library/proxy.spec.ts
index 3a01d101de..ea3087ca3e 100644
--- a/tests/library/proxy.spec.ts
+++ b/tests/library/proxy.spec.ts
@@ -18,8 +18,6 @@ import { setupSocksForwardingServer } from '../config/proxy';
import { playwrightTest as it, expect } from '../config/browserTest';
import net from 'net';
-it.skip(({ mode }) => mode.startsWith('service'));
-
it('should throw for bad server value', async ({ browserType }) => {
const error = await browserType.launch({
// @ts-expect-error server must be a string
diff --git a/tests/library/trace-viewer-scrub.spec.ts b/tests/library/trace-viewer-scrub.spec.ts
index c1c609c055..0b5856d208 100644
--- a/tests/library/trace-viewer-scrub.spec.ts
+++ b/tests/library/trace-viewer-scrub.spec.ts
@@ -21,7 +21,6 @@ import { expect, playwrightTest } from '../config/browserTest';
const test = playwrightTest.extend<TraceViewerFixtures>(traceViewerFixtures);
test.skip(({ trace }) => trace === 'on');
-test.skip(({ mode }) => mode.startsWith('service'));
test.skip(process.env.PW_CLOCK === 'frozen');
test.slow();
diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts
index 1ea2337efc..9e69039b7a 100644
--- a/tests/library/trace-viewer.spec.ts
+++ b/tests/library/trace-viewer.spec.ts
@@ -32,7 +32,6 @@ const test = playwrightTest.extend<TraceViewerFixtures>(traceViewerFixtures);
// NOTE: set PWTEST_DEBUG_TRACE_VIEWER=1 to record/attach traces for these tests.
test.skip(({ trace }) => trace === 'on');
-test.skip(({ mode }) => mode.startsWith('service'));
test.skip(process.env.PW_CLOCK === 'frozen');
test.slow();
diff --git a/tests/library/tracing.spec.ts b/tests/library/tracing.spec.ts
index bd077ed4d5..b565683b6d 100644
--- a/tests/library/tracing.spec.ts
+++ b/tests/library/tracing.spec.ts
@@ -208,8 +208,6 @@ test('should collect two traces', async ({ context, page, server }, testInfo) =>
});
test('should respect tracesDir and name', async ({ browserType, server, mode }, testInfo) => {
- test.skip(mode.startsWith('service'), 'Service ignores tracesDir');
-
const tracesDir = testInfo.outputPath('traces');
const browser = await browserType.launch({ tracesDir });
const context = await browser.newContext();
@@ -717,7 +715,6 @@ test('should store postData for global request', async ({ request, server }, tes
});
test('should not flush console events', async ({ context, page, mode }, testInfo) => {
- test.skip(mode.startsWith('service'), 'Uses artifactsFolderName');
const testId = test.info().testId;
await context.tracing.start({ name: testId });
const promise = new Promise<void>(f => {
@@ -782,8 +779,6 @@ test('should flush console events on tracing stop', async ({ context, page }, te
});
test('should not emit after w/o before', async ({ browserType, mode }, testInfo) => {
- test.skip(mode.startsWith('service'), 'Service ignores tracesDir');
-
const tracesDir = testInfo.outputPath('traces');
const browser = await browserType.launch({ tracesDir });
const context = await browser.newContext();
diff --git a/tests/page/page-event-request.spec.ts b/tests/page/page-event-request.spec.ts
index 263f1f3c50..284c3ebfa4 100644
--- a/tests/page/page-event-request.spec.ts
+++ b/tests/page/page-event-request.spec.ts
@@ -85,7 +85,6 @@ it('should report requests and responses handled by service worker', async ({ pa
it('should report requests and responses handled by service worker with routing', async ({ page, server, isAndroid, isElectron, mode, browserName, platform }) => {
it.fixme(isAndroid);
it.fixme(isElectron);
- it.fixme(mode.startsWith('service') && platform === 'linux', 'Times out for no clear reason');
const interceptedUrls = [];
await page.route('**/*', route => {
diff --git a/tests/page/page-filechooser.spec.ts b/tests/page/page-filechooser.spec.ts
index 6c4262e41d..aa89ec3964 100644
--- a/tests/page/page-filechooser.spec.ts
+++ b/tests/page/page-filechooser.spec.ts
@@ -23,7 +23,6 @@ import formidable from 'formidable';
test('should upload multiple large files', async ({ page, server, isAndroid, mode }, testInfo) => {
test.skip(isAndroid);
- test.skip(mode.startsWith('service'));
test.slow();
const filesCount = 10;
diff --git a/tests/page/page-goto.spec.ts b/tests/page/page-goto.spec.ts
index d6bbad9856..90c0ad8930 100644
--- a/tests/page/page-goto.spec.ts
+++ b/tests/page/page-goto.spec.ts
@@ -26,7 +26,6 @@ it('should work @smoke', async ({ page, server }) => {
it('should work with file URL', async ({ page, asset, isAndroid, mode, channel }) => {
it.skip(isAndroid, 'No files on Android');
- it.skip(mode.startsWith('service'));
it.skip(channel === 'webkit-wsl', 'separate filesystem on wsl');
const fileurl = url.pathToFileURL(asset('empty.html')).href;
@@ -37,7 +36,6 @@ it('should work with file URL', async ({ page, asset, isAndroid, mode, channel }
it('should work with file URL with subframes', async ({ page, asset, isAndroid, mode, channel }) => {
it.skip(isAndroid, 'No files on Android');
- it.skip(mode.startsWith('service'));
it.skip(channel === 'webkit-wsl', 'separate filesystem on wsl');
const fileurl = url.pathToFileURL(asset('frames/two-frames.html')).href;
diff --git a/tests/page/page-history.spec.ts b/tests/page/page-history.spec.ts
index 76e4176431..8d76bb89a6 100644
--- a/tests/page/page-history.spec.ts
+++ b/tests/page/page-history.spec.ts
@@ -54,7 +54,6 @@ it('page.goBack should work with HistoryAPI', async ({ page, server }) => {
it('page.goBack should work for file urls', async ({ page, server, asset, channel, isAndroid, mode }) => {
it.skip(isAndroid, 'No files on Android');
- it.skip(mode.startsWith('service'));
it.skip(channel === 'webkit-wsl');
const url1 = url.pathToFileURL(asset('consolelog.html')).href;
diff --git a/tests/page/page-network-response.spec.ts b/tests/page/page-network-response.spec.ts
index 7eb7e23024..76a5615238 100644
--- a/tests/page/page-network-response.spec.ts
+++ b/tests/page/page-network-response.spec.ts
@@ -253,7 +253,6 @@ it('should behave the same way for headers and allHeaders', async ({ page, serve
it('should provide a Response with a file URL', async ({ page, asset, isAndroid, isElectron, isWindows, browserName, mode, channel }) => {
it.skip(isAndroid, 'No files on Android');
it.skip(browserName === 'firefox', 'Firefox does return null for file:// URLs');
- it.skip(mode.startsWith('service'));
it.skip(channel === 'webkit-wsl');
const fileurl = url.pathToFileURL(asset('frames/two-frames.html')).href;
diff --git a/tests/page/page-set-input-files.spec.ts b/tests/page/page-set-input-files.spec.ts
index c443700b81..b5085c712e 100644
--- a/tests/page/page-set-input-files.spec.ts
+++ b/tests/page/page-set-input-files.spec.ts
@@ -145,7 +145,6 @@ test('should upload a file after popup', async ({ page, server, asset }) => {
test('should upload large file', async ({ page, server, isAndroid, mode }, testInfo) => {
test.skip(isAndroid);
- test.skip(mode.startsWith('service'));
test.slow();
await page.goto(server.PREFIX + '/input/fileupload.html');
@@ -202,7 +201,6 @@ test('should throw an error if the file does not exist', async ({ page, server,
test('should upload large file with relative path', async ({ page, server, isAndroid, mode }, testInfo) => {
test.skip(isAndroid);
- test.skip(mode.startsWith('service'));
test.slow();
await page.goto(server.PREFIX + '/input/fileupload.html');