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
chore: prefer channel browser for ui mode and codegen (#35588)
Yury Semikhatskyc1f1c039d93e
diff --git a/packages/playwright-core/src/server/recorder/recorderApp.ts b/packages/playwright-core/src/server/recorder/recorderApp.tsindex 53563b71a0..3b455e6c9f 100644--- a/packages/playwright-core/src/server/recorder/recorderApp.ts+++ b/packages/playwright-core/src/server/recorder/recorderApp.ts@@ -115,6 +115,8 @@ export class RecorderApp extends EventEmitter implements IRecorderApp {useWebSocket: isUnderTest(),handleSIGINT: recorder.handleSIGINT,executablePath: inspectedContext._browser.options.isChromium ? inspectedContext._browser.options.customExecutablePath : undefined,+ // Use the same channel as the inspected context to guarantee that the browser is installed.+ channel: inspectedContext._browser.options.isChromium ? inspectedContext._browser.options.channel : undefined,}});const controller = new ProgressController(serverSideCallMetadata(), context._browser);diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.tsindex 27d59f0bbd..4ff1dd55ce 100644--- a/packages/playwright/src/runner/testServer.ts+++ b/packages/playwright/src/runner/testServer.ts@@ -442,10 +442,12 @@ export async function runUIMode(configFile: string | undefined, configCLIOverridif (options.host !== undefined || options.port !== undefined) {await openTraceInBrowser(server.urlPrefix('human-readable'));} else {+ const channel = await installedChromiumChannelForUI(configLocation, configCLIOverrides);const page = await openTraceViewerApp(server.urlPrefix('precise'), 'chromium', {headless: isUnderTest() && process.env.PWTEST_HEADED_FOR_TEST !== '1',persistentContextOptions: {handleSIGINT: false,+ channel,},});page.on('close', () => cancelPromise.resolve());@@ -453,6 +455,20 @@ export async function runUIMode(configFile: string | undefined, configCLIOverrid});}+// Pick first channel that is used by one of the projects, to ensure it is installed on the machine.+async function installedChromiumChannelForUI(configLocation: ConfigLocation, configCLIOverrides: ConfigCLIOverrides) {+ const config = await loadConfig(configLocation, configCLIOverrides).catch(e => null);+ if (!config)+ return undefined;+ if (config.projects.some(p => (!p.project.use.browserName || p.project.use.browserName === 'chromium') && !p.project.use.channel))+ return undefined;+ for (const channel of ['chromium', 'chrome', 'msedge']) {+ if (config.projects.some(p => p.project.use.channel === channel))+ return channel;+ }+ return undefined;+}+export async function runTestServer(configFile: string | undefined, configCLIOverrides: ConfigCLIOverrides, options: { host?: string, port?: number }): Promise<reporterTypes.FullResult['status'] | 'restarted'> {const configLocation = resolveConfigLocation(configFile);return await innerRunTestServer(configLocation, configCLIOverrides, options, async server => {@@ -461,7 +477,7 @@ export async function runTestServer(configFile: string | undefined, configCLIOve});}-async function innerRunTestServer(configLocation: ConfigLocation, configCLIOverrides: ConfigCLIOverrides, options: { host?: string, port?: number }, openUI: (server: HttpServer, cancelPromise: ManualPromise<void>, configLocation: ConfigLocation) => Promise<void>): Promise<reporterTypes.FullResult['status'] | 'restarted'> {+async function innerRunTestServer(configLocation: ConfigLocation, configCLIOverrides: ConfigCLIOverrides, options: { host?: string, port?: number }, openUI: (server: HttpServer, cancelPromise: ManualPromise<void>) => Promise<void>): Promise<reporterTypes.FullResult['status'] | 'restarted'> {if (restartWithExperimentalTsEsm(undefined, true))return 'restarted';const testServer = new TestServer(configLocation, configCLIOverrides);@@ -471,7 +487,7 @@ async function innerRunTestServer(configLocation: ConfigLocation, configCLIOverrvoid sigintWatcher.promise().then(() => cancelPromise.resolve());try {const server = await testServer.start(options);- await openUI(server, cancelPromise, configLocation);+ await openUI(server, cancelPromise);await cancelPromise;} finally {await testServer.stop();