Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: fix simulated clock bots (#31301)
Pavel Feldman2a7f17d82061
diff --git a/.github/workflows/tests_others.yml b/.github/workflows/tests_others.ymlindex 04115ce693..783f3fe2ff 100644--- a/.github/workflows/tests_others.yml+++ b/.github/workflows/tests_others.yml@@ -88,11 +88,15 @@ jobs:flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}test_clock_frozen_time_linux:- name: Frozen time library+ name: time library - ${{ matrix.clock }}environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }}permissions:id-token: write # This is required for OIDC login (azure/login) to succeedcontents: read # This is required for actions/checkout to succeed+ strategy:+ fail-fast: false+ matrix:+ clock: [frozen, realtime]runs-on: ubuntu-22.04steps:- uses: actions/checkout@v4@@ -101,32 +105,36 @@ jobs:node-version: 20browsers-to-install: chromiumcommand: npm run test -- --project=chromium-*- bot-name: "frozen-time-library-chromium-linux"+ bot-name: "${{ matrix.clock }}-time-library-chromium-linux"flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }}flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }}flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}env:- PW_FREEZE_TIME: 1+ PW_CLOCK: ${{ matrix.clock }}test_clock_frozen_time_test_runner:- name: Frozen time test runner+ name: time test runner - ${{ matrix.clock }}environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }}runs-on: ubuntu-22.04permissions:id-token: write # This is required for OIDC login (azure/login) to succeedcontents: read # This is required for actions/checkout to succeed+ strategy:+ fail-fast: false+ matrix:+ clock: [frozen, realtime]steps:- uses: actions/checkout@v4- uses: ./.github/actions/run-testwith:node-version: 20command: npm run ttest- bot-name: "frozen-time-runner-chromium-linux"+ bot-name: "${{ matrix.clock }}-time-runner-chromium-linux"flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }}flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }}flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}env:- PW_FREEZE_TIME: 1+ PW_CLOCK: ${{ matrix.clock }}test_electron:name: Electron - ${{ matrix.os }}diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.tsindex b6f55e3b29..7c353656cb 100644--- a/packages/playwright-core/src/client/browser.ts+++ b/packages/playwright-core/src/client/browser.ts@@ -85,11 +85,15 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements apconst 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_FREEZE_TIME) {+ 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-core/src/server/injected/clock.ts b/packages/playwright-core/src/server/injected/clock.tsindex e566597e8d..26342f0223 100644--- a/packages/playwright-core/src/server/injected/clock.ts+++ b/packages/playwright-core/src/server/injected/clock.ts@@ -705,11 +705,12 @@ export function install(globalObject: WindowOrWorkerGlobalScope, config: Install}export function inject(globalObject: WindowOrWorkerGlobalScope) {+ const builtin = platformOriginals(globalObject).bound;const { clock: controller } = install(globalObject);controller.resume();return {controller,- builtin: platformOriginals(globalObject).bound,+ builtin,};}diff --git a/tests/library/browsercontext-add-cookies.spec.ts b/tests/library/browsercontext-add-cookies.spec.tsindex 311084a837..e0ef92a00d 100644--- a/tests/library/browsercontext-add-cookies.spec.ts+++ b/tests/library/browsercontext-add-cookies.spec.ts@@ -391,7 +391,7 @@ it('should(not) block third party cookies', async ({ context, page, server, browit('should not block third party SameSite=None cookies', async ({ contextFactory, httpsServer, browserName }) => {it.skip(browserName === 'webkit', 'No third party cookies in WebKit');- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');const context = await contextFactory({ignoreHTTPSErrors: true,});diff --git a/tests/library/chromium/js-coverage.spec.ts b/tests/library/chromium/js-coverage.spec.tsindex f36e6cbcbb..860304d51c 100644--- a/tests/library/chromium/js-coverage.spec.ts+++ b/tests/library/chromium/js-coverage.spec.ts@@ -43,7 +43,7 @@ it('should ignore eval() scripts by default', async function({ page, server }) {});it('shouldn\'t ignore eval() scripts if reportAnonymousScripts is true', async function({ page, server }) {- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(!!process.env.PW_CLOCK);await page.coverage.startJSCoverage({ reportAnonymousScripts: true });await page.goto(server.PREFIX + '/jscoverage/eval.html');const coverage = await page.coverage.stopJSCoverage();diff --git a/tests/library/headful.spec.ts b/tests/library/headful.spec.tsindex f6e4a28488..cfeb9711c9 100644--- a/tests/library/headful.spec.ts+++ b/tests/library/headful.spec.ts@@ -156,7 +156,7 @@ it('should(not) block third party cookies', async ({ page, server, allowsThirdPait('should not block third party SameSite=None cookies', async ({ httpsServer, browserName, browser }) => {it.skip(browserName === 'webkit', 'No third party cookies in WebKit');- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');const page = await browser.newPage({ignoreHTTPSErrors: true,});diff --git a/tests/page/page-clock.frozen.spec.ts b/tests/page/page-clock.frozen.spec.tsindex bddb794da1..9b70936377 100644--- a/tests/page/page-clock.frozen.spec.ts+++ b/tests/page/page-clock.frozen.spec.ts@@ -16,9 +16,12 @@import { test as it, expect } from './pageTest';-it.skip(!process.env.PW_FREEZE_TIME);-it('clock should be frozen', async ({ page }) => {- await page.clock.setSystemTime(0);- expect(await page.evaluate('Date.now()')).toBe(0);+ it.skip(process.env.PW_CLOCK !== 'frozen');+ expect(await page.evaluate('Date.now()')).toBe(1000);+});++it('clock should be realtime', async ({ page }) => {+ it.skip(process.env.PW_CLOCK !== 'realtime');+ expect(await page.evaluate('Date.now()')).toBeLessThan(1000);});diff --git a/tests/page/page-clock.spec.ts b/tests/page/page-clock.spec.tsindex 670891a40a..220f4725fc 100644--- a/tests/page/page-clock.spec.ts+++ b/tests/page/page-clock.spec.ts@@ -16,7 +16,7 @@import { test, expect } from './pageTest';-test.skip(!!process.env.PW_FREEZE_TIME);+test.skip(!!process.env.PW_CLOCK);declare global {interface Window {diff --git a/tests/page/page-evaluate.spec.ts b/tests/page/page-evaluate.spec.tsindex 8414d23b2c..8bc7a57d17 100644--- a/tests/page/page-evaluate.spec.ts+++ b/tests/page/page-evaluate.spec.ts@@ -362,7 +362,7 @@ it('should properly serialize PerformanceMeasure object', async ({ page }) => {});it('should properly serialize window.performance object', async ({ page }) => {- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(!!process.env.PW_CLOCK);expect(await page.evaluate(() => performance)).toEqual({'navigation': {diff --git a/tests/page/page-goto.spec.ts b/tests/page/page-goto.spec.tsindex 6703d84498..f0a700429d 100644--- a/tests/page/page-goto.spec.ts+++ b/tests/page/page-goto.spec.ts@@ -481,7 +481,7 @@ it('js redirect overrides url bar navigation ', async ({ page, server, browserNait('should succeed on url bar navigation when there is pending navigation', async ({ page, server, browserName }) => {it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');server.setRoute('/a', (req, res) => {res.writeHead(200, { 'content-type': 'text/html' });res.end(`@@ -754,7 +754,7 @@ it('should properly wait for load', async ({ page, server, browserName }) => {it('should not resolve goto upon window.stop()', async ({ browserName, page, server }) => {it.fixme(browserName === 'firefox', 'load/domcontentloaded events are flaky');- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');let response;server.setRoute('/module.js', (req, res) => {@@ -797,7 +797,7 @@ it('should return when navigation is committed if commit is specified', async ({});it('should wait for load when iframe attaches and detaches', async ({ page, server }) => {- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');server.setRoute('/empty.html', (req, res) => {res.writeHead(200, { 'content-type': 'text/html' });res.end(`diff --git a/tests/page/page-history.spec.ts b/tests/page/page-history.spec.tsindex 2bc01512dd..cf6eb2d456 100644--- a/tests/page/page-history.spec.ts+++ b/tests/page/page-history.spec.ts@@ -245,7 +245,7 @@ it('page.goForward during renderer-initiated navigation', async ({ page, serverit('regression test for issue 20791', async ({ page, server }) => {it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/20791' });- it.skip(!!process.env.PW_FREEZE_TIME);+ it.skip(process.env.PW_CLOCK === 'frozen');server.setRoute('/iframe.html', (req, res) => {res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });// iframe access parent frame to log a value from it.