From a1c527df96c4d75bdd62d0fa039355f4d3ec3dbc Mon Sep 17 00:00:00 2001 From: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:21:51 +0100 Subject: [PATCH] test: verify closing last page does not close connection (#12095) Co-authored-by: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> --- test/src/browser.spec.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/src/browser.spec.ts b/test/src/browser.spec.ts index b8e0c8bb077..edfa075c4d3 100644 --- a/test/src/browser.spec.ts +++ b/test/src/browser.spec.ts @@ -6,7 +6,7 @@ import expect from 'expect'; -import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; +import {getTestState, launch, setupTestBrowserHooks} from './mocha-utils.js'; describe('Browser specs', function () { setupTestBrowserHooks(); @@ -64,6 +64,23 @@ describe('Browser specs', function () { expect(remoteBrowser.process()).toBe(null); await remoteBrowser.disconnect(); }); + it('should keep connected after the last page is closed', async () => { + const {browser, close} = await launch({}, {createContext: false}); + try { + const pages = await browser.pages(); + await Promise.all( + pages.map(page => { + return page.close(); + }) + ); + // Verify the browser is still connected. + expect(browser.connected).toBe(true); + // Verify the browser can open a new page. + await browser.newPage(); + } finally { + await close(); + } + }); }); describe('Browser.isConnected', () => {