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
test: unflake console timestamp tests (#39175)
Dmitry Gozmanfb8ce3a84f09
diff --git a/tests/page/page-event-console.spec.ts b/tests/page/page-event-console.spec.tsindex 2831370119..832b1bf24a 100644--- a/tests/page/page-event-console.spec.ts+++ b/tests/page/page-event-console.spec.ts@@ -224,12 +224,12 @@ it('do not update console count on unhandled rejections', async ({ page }) => {});it('should have timestamp', async ({ page }) => {- const before = Date.now();+ const before = Date.now() - 1; // Account for the rounding of fractional timestamps.const [message] = await Promise.all([page.waitForEvent('console'),page.evaluate(() => console.log('timestamp test')),]);- const after = Date.now();+ const after = Date.now() + 1; // Account for the rounding of fractional timestamps.expect(message.timestamp()).toBeGreaterThanOrEqual(before);expect(message.timestamp()).toBeLessThanOrEqual(after);});@@ -248,9 +248,9 @@ it('should have increasing timestamps', async ({ page }) => {});it('should have timestamp in consoleMessages', async ({ page }) => {- const before = Date.now();+ const before = Date.now() - 1; // Account for the rounding of fractional timestamps.await page.evaluate(() => console.log('stored message'));- const after = Date.now();+ const after = Date.now() + 1; // Account for the rounding of fractional timestamps.const messages = await page.consoleMessages();expect(messages.length).toBeGreaterThanOrEqual(1);const last = messages[messages.length - 1];diff --git a/tests/page/workers.spec.ts b/tests/page/workers.spec.tsindex 1918981dce..ccef5e28e0 100644--- a/tests/page/workers.spec.ts+++ b/tests/page/workers.spec.ts@@ -61,12 +61,12 @@ it('should report console logs', async function({ page }) {});it('should have timestamp on worker console messages', async function({ page }) {- const before = Date.now();+ const before = Date.now() - 1; // Account for the rounding of fractional timestamps.const [message] = await Promise.all([page.waitForEvent('console'),page.evaluate(() => new Worker(URL.createObjectURL(new Blob(['console.log("ts")'], { type: 'application/javascript' })))),]);- const after = Date.now();+ const after = Date.now() + 1; // Account for the rounding of fractional timestamps.expect(message.text()).toBe('ts');expect(message.timestamp()).toBeGreaterThanOrEqual(before);expect(message.timestamp()).toBeLessThanOrEqual(after);