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
test: move browser._launchServer in child process (#37114)
Simon Knottface8d44ea0b
diff --git a/tests/config/remote-server-impl.js b/tests/config/remote-server-impl.jsindex baf6d946b9..e77ed89395 100644--- a/tests/config/remote-server-impl.js+++ b/tests/config/remote-server-impl.js@@ -2,7 +2,8 @@ const fs = require('fs');const cluster = require('cluster');async function start() {- const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP, exitOnFile, exitOnWarning, startStopAndRunHttp } = JSON.parse(process.argv[2]);+ /** @type {import("./remoteServer").RemoteServerOptions} */+ const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP, exitOnFile, exitOnWarning, startStopAndRunHttp, existingBrowser } = JSON.parse(process.argv[2]);if (stallOnClose) {launchOptions.__testHookGracefullyClose = () => {console.log(`(stalled=>true)`);@@ -25,7 +26,15 @@ async function start() {return;}- const browserServer = await playwright[browserTypeName].launchServer(launchOptions);+ let browserServer;+ if (existingBrowser) {+ const browser = await playwright[browserTypeName].launch(launchOptions);+ const page = await browser.newPage();+ await page.setContent(existingBrowser.content);+ browserServer = await browser._launchServer();+ } else {+ browserServer = await playwright[browserTypeName].launchServer(launchOptions);+ }if (disconnectOnSIGHUP)process.on('SIGHUP', () => browserServer._disconnectForTest());diff --git a/tests/config/remoteServer.ts b/tests/config/remoteServer.tsindex 4c25934581..2e9ec35d2a 100644--- a/tests/config/remoteServer.ts+++ b/tests/config/remoteServer.ts@@ -69,6 +69,7 @@ export type RemoteServerOptions = {url?: string;startStopAndRunHttp?: boolean;sharedBrowser?: boolean;+ existingBrowser?: { content: string };};export class RemoteServer implements PlaywrightServer {diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.tsindex 826bc07df9..98dcc6e807 100644--- a/tests/library/browsertype-connect.spec.ts+++ b/tests/library/browsertype-connect.spec.ts@@ -1047,18 +1047,12 @@ test.describe('launchServer only', () => {await expect(browser._parent.launch({ timeout: 0 })).rejects.toThrowError('Launching more browsers is not allowed.');});- test('should work with existing browser', async ({ connect, browserType, mode }) => {+ test('should work with existing browser', async ({ connect, startRemoteServer, mode }) => {test.skip(mode === 'driver', 'Driver mode does not support browserType.launchServer');- // can't use browser fixture because it's shared across the worker, launching a server on that would infect other tests- const browser = await browserType.launch();- const page = await browser.newPage();- await page.setContent('hello world');- const server = await (browser as any)._launchServer();- const secondBrowser = await connect(server.wsEndpoint());- const secondPage = secondBrowser.contexts()[0].pages()[0];- expect(await secondPage.content()).toContain('hello world');- await server.close();- await browser.close();+ const remoteServer = await startRemoteServer('launchServer', { existingBrowser: { content: 'hello world' } });+ const browser = await connect(remoteServer.wsEndpoint());+ const page = browser.contexts()[0].pages()[0];+ expect(await page.content()).toContain('hello world');});});