From eb980207fc037b38477a0b8d5948764424e4b086 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 1 Mar 2021 11:05:02 -0800 Subject: [PATCH] test: add a test for 2 cdp sessions against the browser (#5655) --- test/chromium/chromium.spec.ts | 46 +++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/test/chromium/chromium.spec.ts b/test/chromium/chromium.spec.ts index 6a98a915de..862f0a2630 100644 --- a/test/chromium/chromium.spec.ts +++ b/test/chromium/chromium.spec.ts @@ -91,9 +91,7 @@ describe('chromium', (suite, { browserName }) => { expect(serverRequest.headers.intervention).toContain('feature/5718547946799104'); }); - it('should connect to an existing cdp session', (test, {headful}) => { - test.skip(headful, 'Chromium currently doesn\'t support --remote-debugging-port and --remote-debugging-pipe at the same time.'); - }, async ({browserType, testWorkerIndex, browserOptions, createUserDataDir }) => { + it('should connect to an existing cdp session', async ({browserType, testWorkerIndex, browserOptions }) => { const port = 9339 + testWorkerIndex; const browserServer = await browserType.launch({ ...browserOptions, @@ -117,4 +115,46 @@ describe('chromium', (suite, { browserName }) => { await browserServer.close(); } }); + + it('should connect to an existing cdp session twice', async ({browserType, testWorkerIndex, browserOptions, server }) => { + const port = 9339 + testWorkerIndex; + const browserServer = await browserType.launch({ + ...browserOptions, + args: ['--remote-debugging-port=' + port] + }); + try { + const json = await new Promise((resolve, reject) => { + http.get(`http://localhost:${port}/json/version/`, resp => { + let data = ''; + resp.on('data', chunk => data += chunk); + resp.on('end', () => resolve(data)); + }).on('error', reject); + }); + const cdpBrowser1 = await browserType.connectOverCDP({ + wsEndpoint: JSON.parse(json).webSocketDebuggerUrl, + }); + const cdpBrowser2 = await browserType.connectOverCDP({ + wsEndpoint: JSON.parse(json).webSocketDebuggerUrl, + }); + const contexts1 = cdpBrowser1.contexts(); + expect(contexts1.length).toBe(1); + const [context1] = contexts1; + const page1 = await context1.newPage(); + await page1.goto(server.EMPTY_PAGE); + + const contexts2 = cdpBrowser2.contexts(); + expect(contexts2.length).toBe(1); + const [context2] = contexts2; + const page2 = await context2.newPage(); + await page2.goto(server.EMPTY_PAGE); + + expect(context1.pages().length).toBe(2); + expect(context2.pages().length).toBe(2); + + await cdpBrowser1.close(); + await cdpBrowser2.close(); + } finally { + await browserServer.close(); + } + }); });