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 android tests (#41301)

Dmitry Gozmanb7749c26110d
diff --git a/tests/android/androidTest.ts b/tests/android/androidTest.ts
index 4dd0c2c7d4..71949daab5 100644
--- a/tests/android/androidTest.ts
+++ b/tests/android/androidTest.ts
@@ -81,8 +81,14 @@ export const androidTest = baseTest.extend<PageTestFixtures & AndroidTestFixture
// Retain default page, otherwise Clank will re-create it.
while (androidContext.pages().length > 1)
await androidContext.pages()[1].close();
- const page = await androidContext.newPage();
- await run(page);
+ await run(await androidContext.newPage());
+ const pages = androidContext.pages();
+ // Keep one fresh page - Clank does not like having zero pages.
+ await androidContext.newPage();
+ // Close all existing pages that could be stuck in a navigation, have an open dialog, etc.
+ for (const page of pages)
+ await page.close();
+ // Cleanup as much as we can. This requires a non-stuck page that can respond to CDP.
await androidContext.setStorageState({ cookies: [], origins: [] });
},
});
diff --git a/tests/library/har-websocket.spec.ts b/tests/library/har-websocket.spec.ts
index 37799ba4ea..d33f766c87 100644
--- a/tests/library/har-websocket.spec.ts
+++ b/tests/library/har-websocket.spec.ts
@@ -449,7 +449,9 @@ it('should still allow routeWebSocket to modify messages when capturing HAR', as
]);
});
-it('should respect PLAYWRIGHT_HAR_NO_WEBSOCKET_FRAMES', async ({ contextFactory, server }, testInfo) => {
+it('should respect PLAYWRIGHT_HAR_NO_WEBSOCKET_FRAMES', async ({ contextFactory, server, mode }, testInfo) => {
+ it.skip(mode !== 'default', 'no env vars in non-default mode');
+
process.env.PLAYWRIGHT_HAR_NO_WEBSOCKET_FRAMES = '1';
server.onceWebSocketConnection(ws => {
ws.on('message', () => ws.close());
diff --git a/tests/page/page-wait-for-selector-2.spec.ts b/tests/page/page-wait-for-selector-2.spec.ts
index 4f473f86f2..8a8955a7e3 100644
--- a/tests/page/page-wait-for-selector-2.spec.ts
+++ b/tests/page/page-wait-for-selector-2.spec.ts
@@ -343,7 +343,7 @@ it('should succeed if element handle was detached while waiting for hidden', asy
await page.setContent(`<button>hello</button>`);
const button = await page.$('button');
const promise = button.waitForSelector('something', { state: 'hidden' });
- await page.waitForTimeout(100);
+ await page.waitForTimeout(1000);
await page.evaluate(() => document.body.innerText = '');
await promise;
});
@@ -352,7 +352,7 @@ it('should succeed if element handle was detached while waiting for detached', a
await page.setContent(`<button>hello</button>`);
const button = await page.$('button');
const promise = button.waitForSelector('something', { state: 'detached' });
- await page.waitForTimeout(100);
+ await page.waitForTimeout(1000);
await page.evaluate(() => document.body.innerText = '');
await promise;
});