Skip to content

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

test: unflake tests (#37580)

Max Schmitt89af5a7c2486
diff --git a/tests/library/defaultbrowsercontext-2.spec.ts b/tests/library/defaultbrowsercontext-2.spec.ts
index fbaab6419c..6775d26b67 100644
--- a/tests/library/defaultbrowsercontext-2.spec.ts
+++ b/tests/library/defaultbrowsercontext-2.spec.ts
@@ -116,6 +116,9 @@ it('should restore state from userDataDir', async ({ browserType, server, create
const page = await browserContext.newPage();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => localStorage.hey = 'hello');
+ // Browsers do not persist local storage immediately, they do it asynchronously in another process.
+ // Navigate away to give it a chance to save (best-effort).
+ await page.goto(server.EMPTY_PAGE);
await browserContext.close();
const browserContext2 = await browserType.launchPersistentContext(userDataDir);
diff --git a/tests/mcp/files.spec.ts b/tests/mcp/files.spec.ts
index a632209524..6677a44027 100644
--- a/tests/mcp/files.spec.ts
+++ b/tests/mcp/files.spec.ts
@@ -127,11 +127,11 @@ test('clicking on download link emits download', async ({ startClient, server },
});
test('navigating to download link emits download', async ({ startClient, server, mcpBrowser }, testInfo) => {
+ test.skip(mcpBrowser !== 'chromium', 'This test is racy');
const { client } = await startClient({
config: { outputDir: testInfo.outputPath('output') },
});
- test.skip(mcpBrowser !== 'chromium', 'This test is racy');
server.setRoute('/download', (req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain',