Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tests/webview/webviewTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import { spawnSync } from 'child_process';
import fs from 'fs';
import path from 'path';

import { iso } from '../../packages/playwright-core/lib/coreBundle';
import { baseTest } from '../config/baseTest';
import { loadWebViewExpectations, shouldSkipWebViewTest, type WebViewExpectation } from './expectationUtil';
import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi';
export { expect } from '@playwright/test';

const { raceAgainstDeadline } = iso;

const PROXY_BASE = process.env.PW_WEBVIEW_PROXY_BASE || 'http://localhost:9222';

type WebViewWorkerFixtures = PageWorkerFixtures & {
Expand Down Expand Up @@ -138,7 +141,7 @@ export const webviewTest = baseTest.extend<WebViewTestFixtures, WebViewWorkerFix
await run(endpoint);
}, { scope: 'worker', timeout: 180000 }],

page: async ({ playwright, webviewEndpoint }, run) => {
page: async ({ playwright, webviewEndpoint }, run, testInfo) => {
const browser = await playwright.webkit.connectOverCDP(webviewEndpoint);
const [context] = browser.contexts();
const pages = context.pages();
Expand All @@ -148,9 +151,12 @@ export const webviewTest = baseTest.extend<WebViewTestFixtures, WebViewWorkerFix
throw new Error('No Mobile Safari tab is attached');
await page.goto('about:blank').catch(() => {});
await run(page);
// The shared Mobile Safari cookie store persists across tests; clear it
// while still on the test's domain (webview cookies are domain-scoped).
await page.context().clearCookies().catch(() => {});
// The shared Mobile Safari cookie store persists across tests; clear it while

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I follow: this does not clear any tests, does not do proper cleanup for all the visited origins either. If there is a clean way to implement it (reset for reuse-alike), let's do it. Otherwise, let's not add this code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless something has otherwise changed, tests/page/page-set-content.spec.ts:153:3 › should handle timeout properly is a frequent timeout failure when running tests

so yes this does not enable any previously skipped tests, but it does fix a (previously) known flaky test

// still on the test's domain (webview cookies are domain-scoped). A test that
// wedges the page's main thread stalls the inspector protocol, so cap this at
// the remaining test timeout, reserving a moment for `browser.close()` below.
const { deadline } = (testInfo as unknown as { _deadline(): { deadline: number } })._deadline();
await raceAgainstDeadline(() => page.context().clearCookies().catch(() => {}), deadline - 250);
await browser.close();
},

Expand Down
Loading