Skip to content

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

test: fix/unflake some tests (#38496)

Dmitry Gozmane894c5f8c3b2
diff --git a/tests/library/capabilities.spec.ts b/tests/library/capabilities.spec.ts
index 2fd3610bc4..c7c7fde49f 100644
--- a/tests/library/capabilities.spec.ts
+++ b/tests/library/capabilities.spec.ts
@@ -469,7 +469,7 @@ it('should not auto play audio', {
});
await page.goto('http://127.0.0.1/audio.html');
if (browserName === 'webkit')
- await expect(page.locator('#log')).toHaveText('State: interrupted');
+ await expect(page.locator('#log')).toHaveText(/State: (interrupted|suspended)/);
else
await expect(page.locator('#log')).toHaveText('State: suspended');
});
diff --git a/tests/library/chromium/chromium.spec.ts b/tests/library/chromium/chromium.spec.ts
index 19dd5d708e..1433857ead 100644
--- a/tests/library/chromium/chromium.spec.ts
+++ b/tests/library/chromium/chromium.spec.ts
@@ -625,9 +625,10 @@ test('setExtraHTTPHeaders', async ({ context, page, server }) => {
expect(req.headers['x-custom-header']).toBe('custom!');
});
-test('should throw when connecting twice to an already running persistent context (--remote-debugging-port)', async ({ browserType, createUserDataDir, platform, isHeadlessShell }) => {
+test('should throw when connecting twice to an already running persistent context (--remote-debugging-port)', async ({ browserType, createUserDataDir, platform, isHeadlessShell, channel }) => {
test.skip(isHeadlessShell, 'Headless shell does not create a ProcessSingleton');
test.fixme(platform === 'win32', 'Windows does not print something to the console when the profile is already in use by another instance of Chromium.');
+ test.skip(!!channel?.startsWith('msedge'), 'Edge does not print the ProcessSingleton line');
const userDataDir = await createUserDataDir();
const browser = await browserType.launchPersistentContext(userDataDir, {
cdpPort: 9222,
@@ -642,9 +643,10 @@ test('should throw when connecting twice to an already running persistent contex
}
});
-test('should throw when connecting twice to an already running persistent context (--remote-debugging-pipe)', async ({ browserType, createUserDataDir, platform, isHeadlessShell }) => {
+test('should throw when connecting twice to an already running persistent context (--remote-debugging-pipe)', async ({ browserType, createUserDataDir, platform, isHeadlessShell, channel }) => {
test.skip(isHeadlessShell, 'Headless shell does not create a ProcessSingleton');
test.fixme(platform === 'win32', 'Windows does not print something to the console when the profile is already in use by another instance of Chromium.');
+ test.skip(!!channel?.startsWith('msedge'), 'Edge does not print the ProcessSingleton line');
const userDataDir = await createUserDataDir();
const browser = await browserType.launchPersistentContext(userDataDir);
try {
diff --git a/tests/library/chromium/tracing.spec.ts b/tests/library/chromium/tracing.spec.ts
index f933ebbe2c..9a39774fb6 100644
--- a/tests/library/chromium/tracing.spec.ts
+++ b/tests/library/chromium/tracing.spec.ts
@@ -102,6 +102,6 @@ it('should support a buffer without a path', async ({ browser, server }) => {
await page.goto(server.PREFIX + '/grid.html');
await rafraf(page);
const trace = await browser.stopTracing();
- expect(trace.toString()).toContain('screenshot');
+ expect(trace.toString().includes('screenshot')).toBe(true);
await page.close();
});
diff --git a/tests/playwright-test/max-failures.spec.ts b/tests/playwright-test/max-failures.spec.ts
index fed320b826..56ad9f466f 100644
--- a/tests/playwright-test/max-failures.spec.ts
+++ b/tests/playwright-test/max-failures.spec.ts
@@ -186,20 +186,20 @@ test('max-failures should not consider retries as failures', async ({ runInlineT
const result = await runInlineTest({
'playwright.config.ts': `
export default {
- maxFailures: 10,
- retries: 10,
+ maxFailures: 5,
+ retries: 5,
};
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
test('I fail 9 times 1', () => {
- if (test.info().retry < 9)
+ if (test.info().retry < 4)
throw new Error('failing intentionally');
});
test('I fail 9 times 2', () => {
- if (test.info().retry < 9)
+ if (test.info().retry < 4)
throw new Error('failing intentionally');
});
`,