diff --git a/test/src/cdp/CDPSession.spec.ts b/test/src/cdp/CDPSession.spec.ts index 2000c0e4351..887152f0978 100644 --- a/test/src/cdp/CDPSession.spec.ts +++ b/test/src/cdp/CDPSession.spec.ts @@ -30,7 +30,7 @@ describe('Target.createCDPSession', function () { }); it('should not report created targets for custom CDP sessions', async () => { - const {browser} = await getTestState(); + const {context} = await getTestState(); let called = 0; const handler = async (target: Target) => { called++; @@ -39,9 +39,9 @@ describe('Target.createCDPSession', function () { } await target.createCDPSession(); }; - browser.browserContexts()[0]!.on('targetcreated', handler); - await browser.newPage(); - browser.browserContexts()[0]!.off('targetcreated', handler); + context.on('targetcreated', handler); + await context.newPage(); + context.off('targetcreated', handler); }); it('should send events', async () => { diff --git a/test/src/headful.spec.ts b/test/src/headful.spec.ts index 1e3248b4ff6..e5d109bb656 100644 --- a/test/src/headful.spec.ts +++ b/test/src/headful.spec.ts @@ -64,23 +64,30 @@ const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-'); const headfulBrowser = await launchBrowser( Object.assign({userDataDir}, headfulOptions) ); - const headfulPage = await headfulBrowser.newPage(); - await headfulPage.goto(server.EMPTY_PAGE); - await headfulPage.evaluate(() => { - return (document.cookie = - 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT'); - }); - await headfulBrowser.close(); + try { + const headfulPage = await headfulBrowser.newPage(); + await headfulPage.goto(server.EMPTY_PAGE); + await headfulPage.evaluate(() => { + return (document.cookie = + 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT'); + }); + } finally { + await headfulBrowser.close(); + } // Read the cookie from headless chrome const headlessBrowser = await launchBrowser( Object.assign({userDataDir}, headlessOptions) ); - const headlessPage = await headlessBrowser.newPage(); - await headlessPage.goto(server.EMPTY_PAGE); - const cookie = await headlessPage.evaluate(() => { - return document.cookie; - }); - await headlessBrowser.close(); + let cookie = ''; + try { + const headlessPage = await headlessBrowser.newPage(); + await headlessPage.goto(server.EMPTY_PAGE); + cookie = await headlessPage.evaluate(() => { + return document.cookie; + }); + } finally { + await headlessBrowser.close(); + } // This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 try { rmSync(userDataDir); diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index 7f3736709eb..85501dc988a 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -42,9 +42,9 @@ describe('Page', function () { expect(error.message).toContain('Protocol error'); }); it('should not be visible in browser.pages', async () => { - const {browser} = await getTestState(); + const {browser, context} = await getTestState(); - const newPage = await browser.newPage(); + const newPage = await context.newPage(); expect(await browser.pages()).toContain(newPage); await newPage.close(); expect(await browser.pages()).not.toContain(newPage); @@ -2239,9 +2239,9 @@ describe('Page', function () { describe('Page.bringToFront', function () { it('should work', async () => { - const {browser} = await getTestState(); - const page1 = await browser.newPage(); - const page2 = await browser.newPage(); + const {context} = await getTestState(); + const page1 = await context.newPage(); + const page2 = await context.newPage(); await page1.bringToFront(); expect( diff --git a/test/src/target.spec.ts b/test/src/target.spec.ts index 28d17a4030f..fe900246512 100644 --- a/test/src/target.spec.ts +++ b/test/src/target.spec.ts @@ -285,7 +285,7 @@ describe('Target', function () { describe('Browser.waitForTarget', () => { it('should wait for a target', async () => { - const {browser, server} = await getTestState(); + const {browser, server, context} = await getTestState(); let resolved = false; const targetPromise = browser.waitForTarget( @@ -306,7 +306,7 @@ describe('Target', function () { throw error; } }); - const page = await browser.newPage(); + const page = await context.newPage(); expect(resolved).toBe(false); await page.goto(server.EMPTY_PAGE); try {