Skip to content

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

test(clock): fix clock mode bots (#31472)

Pavel Feldmanf46ae15500df
diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.ts
index 7c353656cb..be47ddeb51 100644
--- a/packages/playwright-core/src/client/browser.ts
+++ b/packages/playwright-core/src/client/browser.ts
@@ -85,16 +85,6 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
const context = BrowserContext.from(response.context);
await this._browserType._didCreateContext(context, contextOptions, this._options, options.logger || this._logger);
- if (!forReuse && process.env.PW_CLOCK === 'frozen') {
- await this._wrapApiCall(async () => {
- await context.clock.install({ time: 0 });
- await context.clock.pauseAt(1000);
- }, true);
- } else if (!forReuse && process.env.PW_CLOCK === 'realtime') {
- await this._wrapApiCall(async () => {
- await context.clock.install({ time: 0 });
- }, true);
- }
return context;
}
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index 2e1236d8ea..a258cbcad5 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -274,6 +274,18 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
contexts.set(context, contextData);
if (captureVideo)
context.on('page', page => contextData.pagesWithVideo.push(page));
+
+ if (process.env.PW_CLOCK === 'frozen') {
+ await (context as any)._wrapApiCall(async () => {
+ await context.clock.install({ time: 0 });
+ await context.clock.pauseAt(1000);
+ }, true);
+ } else if (process.env.PW_CLOCK === 'realtime') {
+ await (context as any)._wrapApiCall(async () => {
+ await context.clock.install({ time: 0 });
+ }, true);
+ }
+
return context;
});
diff --git a/tests/page/page-clock.frozen.spec.ts b/tests/page/page-clock.frozen.spec.ts
index 9b70936377..b9b319cd63 100644
--- a/tests/page/page-clock.frozen.spec.ts
+++ b/tests/page/page-clock.frozen.spec.ts
@@ -23,5 +23,5 @@ it('clock should be frozen', async ({ page }) => {
it('clock should be realtime', async ({ page }) => {
it.skip(process.env.PW_CLOCK !== 'realtime');
- expect(await page.evaluate('Date.now()')).toBeLessThan(1000);
+ expect(await page.evaluate('Date.now()')).toBeLessThan(10000);
});
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 83992c0bad..e416cd05c1 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -294,6 +294,7 @@ for (const useIntermediateMergeReport of [false] as const) {
});
test('should include image diff when screenshot failed to generate due to animation', async ({ runInlineTest, page, showReport }) => {
+ test.skip(process.env.PW_CLOCK === 'frozen', 'Assumes Date.now() changes');
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { viewport: { width: 200, height: 200 }} };