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(test): move more test options to state (#1761)
Dmitry Gozman62a493ecbd49
diff --git a/test/chromium/launcher.spec.js b/test/chromium/launcher.spec.jsindex 134b456dc4..337472cfea 100644--- a/test/chromium/launcher.spec.js+++ b/test/chromium/launcher.spec.js@@ -17,35 +17,23 @@const path = require('path');const utils = require('../utils');const {makeUserDataDir, removeUserDataDir} = utils;-const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions} = utils.testOptions(browserType);--const headfulOptions = Object.assign({}, defaultBrowserOptions, {- headless: false-});-const extensionPath = path.join(__dirname, '..', 'assets', 'simple-extension');-const extensionOptions = Object.assign({}, defaultBrowserOptions, {- headless: false,- args: [- `--disable-extensions-except=${extensionPath}`,- `--load-extension=${extensionPath}`,- ],-});+const {FFOX, CHROMIUM, WEBKIT, WIN} = utils.testOptions(browserType);describe('launcher', function() {- it('should throw with remote-debugging-pipe argument', async({browserType}) => {+ it('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => {const options = Object.assign({}, defaultBrowserOptions);options.args = ['--remote-debugging-pipe'].concat(options.args || []);const error = await browserType.launchServer(options).catch(e => e);expect(error.message).toContain('Playwright manages remote debugging connection itself');});- it('should throw with remote-debugging-port argument', async({browserType}) => {+ it('should throw with remote-debugging-port argument', async({browserType, defaultBrowserOptions}) => {const options = Object.assign({}, defaultBrowserOptions);options.args = ['--remote-debugging-port=9222'].concat(options.args || []);const error = await browserType.launchServer(options).catch(e => e);expect(error.message).toContain('Playwright manages remote debugging connection itself');});- it('should open devtools when "devtools: true" option is given', async({browserType}) => {- const browser = await browserType.launch(Object.assign({devtools: true}, headfulOptions));+ it('should open devtools when "devtools: true" option is given', async({browserType, defaultBrowserOptions}) => {+ const browser = await browserType.launch(Object.assign({devtools: true}, {...defaultBrowserOptions, headless: false}));const context = await browser.newContext();const browserSession = await browser.newBrowserCDPSession();await browserSession.send('Target.setDiscoverTargets', { discover: true });@@ -62,8 +50,16 @@ describe('launcher', function() {});describe('extensions', () => {- it('should return background pages', async({browserType}) => {+ it('should return background pages', async({browserType, defaultBrowserOptions}) => {const userDataDir = await makeUserDataDir();+ const extensionPath = path.join(__dirname, '..', 'assets', 'simple-extension');+ const extensionOptions = {...defaultBrowserOptions,+ headless: false,+ args: [+ `--disable-extensions-except=${extensionPath}`,+ `--load-extension=${extensionPath}`,+ ],+ };const context = await browserType.launchPersistentContext(userDataDir, extensionOptions);const backgroundPages = context.backgroundPages();let backgroundPage = backgroundPages.lengthdiff --git a/test/chromium/oopif.spec.js b/test/chromium/oopif.spec.jsindex d1d0daaee1..79f920cbe7 100644--- a/test/chromium/oopif.spec.js+++ b/test/chromium/oopif.spec.js@@ -14,16 +14,12 @@* limitations under the License.*/-const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('../utils').testOptions(browserType);--const headfulOptions = Object.assign({}, defaultBrowserOptions, {- headless: false-});+const {FFOX, CHROMIUM, WEBKIT} = require('../utils').testOptions(browserType);describe('OOPIF', function() {beforeAll(async function(state) {- state.browser = await state.browserType.launch(Object.assign({}, defaultBrowserOptions, {- args: (defaultBrowserOptions.args || []).concat(['--site-per-process']),+ state.browser = await state.browserType.launch(Object.assign({}, state.defaultBrowserOptions, {+ args: (state.defaultBrowserOptions.args || []).concat(['--site-per-process']),}));});beforeEach(async function(state) {@@ -72,10 +68,10 @@ describe('OOPIF', function() {await page.click('button');expect(await page.evaluate(() => window.BUTTON_CLICKED)).toBe(true);});- it('should report google.com frame with headful', async({browserType, server}) => {+ it('should report google.com frame with headful', async({browserType, defaultBrowserOptions, server}) => {// TODO: Support OOOPIF. @see https://github.com/GoogleChrome/puppeteer/issues/2548// https://google.com is isolated by default in Chromium embedder.- const browser = await browserType.launch(headfulOptions);+ const browser = await browserType.launch({...defaultBrowserOptions, headless: false});const page = await browser.newPage();await page.goto(server.EMPTY_PAGE);await page.route('**/*', route => {diff --git a/test/chromium/pdf.spec.js b/test/chromium/pdf.spec.jsindex e901a398ed..3a5cf33614 100644--- a/test/chromium/pdf.spec.js+++ b/test/chromium/pdf.spec.js@@ -16,10 +16,10 @@const fs = require('fs');const path = require('path');-const {FFOX, CHROMIUM, WEBKIT, headless, OUTPUT_DIR} = require('../utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR} = require('../utils').testOptions(browserType);// Printing to pdf is currently only supported in headless-describe.fail(!headless)('Page.pdf', function() {+describe('Page.pdf', function() {it('should be able to save file', async({page, server}) => {const outputFile = path.join(OUTPUT_DIR, 'output.pdf');await page.pdf({path: outputFile});diff --git a/test/chromium/tracing.spec.js b/test/chromium/tracing.spec.jsindex 26f760c319..23deb23de4 100644--- a/test/chromium/tracing.spec.js+++ b/test/chromium/tracing.spec.js@@ -16,12 +16,12 @@const fs = require('fs');const path = require('path');-const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR, defaultBrowserOptions} = require('../utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR} = require('../utils').testOptions(browserType);describe('Chromium.startTracing', function() {beforeEach(async function(state) {state.outputFile = path.join(OUTPUT_DIR, `trace-${state.parallelIndex}.json`);- state.browser = await state.browserType.launch(defaultBrowserOptions);+ state.browser = await state.browserType.launch(state.defaultBrowserOptions);state.page = await state.browser.newPage();});afterEach(async function(state) {diff --git a/test/cookies.spec.js b/test/cookies.spec.jsindex 2fab64b538..d94715c804 100644--- a/test/cookies.spec.js+++ b/test/cookies.spec.js@@ -15,7 +15,7 @@* limitations under the License.*/-const {FFOX, CHROMIUM, WEBKIT, MAC, defaultBrowserOptions} = require('./utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);describe('BrowserContext.cookies', function() {it('should return no cookies in pristine browser context', async({context, page, server}) => {@@ -269,7 +269,7 @@ describe('BrowserContext.addCookies', function() {await context.close();}});- it.slow()('should isolate cookies between launches', async({browserType, server}) => {+ it.slow()('should isolate cookies between launches', async({browserType, server, defaultBrowserOptions}) => {const browser1 = await browserType.launch(defaultBrowserOptions);const context1 = await browser1.newContext();await context1.addCookies([{url: server.EMPTY_PAGE, name: 'cookie-in-context-1', value: 'value', expires: Date.now() / 1000 + 10000}]);diff --git a/test/defaultbrowsercontext.spec.js b/test/defaultbrowsercontext.spec.jsindex c578cd6591..976a050d37 100644--- a/test/defaultbrowsercontext.spec.js+++ b/test/defaultbrowsercontext.spec.js@@ -17,12 +17,12 @@const utils = require('./utils');const {makeUserDataDir, removeUserDataDir} = utils;-const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = utils.testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);describe('launchPersistentContext()', function() {beforeEach(async state => {state.userDataDir = await makeUserDataDir();- state.browserContext = await state.browserType.launchPersistentContext(state.userDataDir, defaultBrowserOptions);+ state.browserContext = await state.browserType.launchPersistentContext(state.userDataDir, state.defaultBrowserOptions);state.page = await state.browserContext.newPage();});afterEach(async state => {diff --git a/test/download.spec.js b/test/download.spec.jsindex 7796783b1e..da30d10d09 100644--- a/test/download.spec.js+++ b/test/download.spec.js@@ -16,7 +16,7 @@const fs = require('fs');const path = require('path');-const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('./utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);describe('Download', function() {beforeEach(async(state) => {@@ -98,7 +98,7 @@ describe('Download', function() {expect(fs.existsSync(path1)).toBeFalsy();expect(fs.existsSync(path2)).toBeFalsy();});- it('should delete downloads on browser gone', async ({ server, browserType }) => {+ it('should delete downloads on browser gone', async ({ server, browserType, defaultBrowserOptions }) => {const browser = await browserType.launch(defaultBrowserOptions);const page = await browser.newPage({ acceptDownloads: true });await page.setContent(`<a download=true href="${server.PREFIX}/download">download</a>`);diff --git a/test/emulation.spec.js b/test/emulation.spec.jsindex 9e20033cbc..7d06957e64 100644--- a/test/emulation.spec.js+++ b/test/emulation.spec.js@@ -16,7 +16,7 @@*/const utils = require('./utils');-const {FFOX, CHROMIUM, WEBKIT, headless} = utils.testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);const iPhone = playwright.devices['iPhone 6'];const iPhoneLandscape = playwright.devices['iPhone 6 landscape'];@@ -446,7 +446,7 @@ describe('BrowserContext({locale})', function() {});});-describe.fail(!headless)('focus', function() {+describe('focus', function() {it('should think that it is focused by default', async({page}) => {expect(await page.evaluate('document.hasFocus()')).toBe(true);});diff --git a/test/fixtures.spec.js b/test/fixtures.spec.jsindex 89e3ad3d24..0860c7593f 100644--- a/test/fixtures.spec.js+++ b/test/fixtures.spec.js@@ -17,18 +17,18 @@const path = require('path');const {spawn, execSync} = require('child_process');-const {FFOX, CHROMIUM, WEBKIT, WIN, playwrightPath, defaultBrowserOptions} = require('./utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT, WIN} = require('./utils').testOptions(browserType);-async function testSignal(browserType, action, exitOnClose) {- const options = Object.assign({}, defaultBrowserOptions, {+async function testSignal(state, action, exitOnClose) {+ const options = Object.assign({}, state.defaultBrowserOptions, {// Disable DUMPIO to cleanly read stdout.dumpio: false,handleSIGINT: true,handleSIGTERM: true,handleSIGHUP: true,- executablePath: browserType.executablePath(),+ executablePath: state.browserType.executablePath(),});- const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, browserType.name(), JSON.stringify(options), exitOnClose ? 'true' : '']);+ const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), state.playwrightPath, state.browserType.name(), JSON.stringify(options), exitOnClose ? 'true' : '']);let wsEndPointCallback;const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);let output = '';@@ -52,7 +52,7 @@ async function testSignal(browserType, action, exitOnClose) {browserPid = +match[1];});res.on('error', (...args) => console.log("ERROR", ...args));- const browser = await browserType.connect({ wsEndpoint: await wsEndPointPromise });+ const browser = await state.browserType.connect({ wsEndpoint: await wsEndPointPromise });const promises = [new Promise(resolve => browser.once('disconnected', resolve)),new Promise(resolve => res.on('exit', resolve)),@@ -63,15 +63,15 @@ async function testSignal(browserType, action, exitOnClose) {}describe('Fixtures', function() {- it.slow()('should dump browser process stderr', async({browserType}) => {+ it.slow()('should dump browser process stderr', async state => {let dumpioData = '';- const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, browserType.name()]);+ const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), state.playwrightPath, state.browserType.name()]);res.stdout.on('data', data => dumpioData += data.toString('utf8'));await new Promise(resolve => res.on('close', resolve));expect(dumpioData).toContain('message from dumpio');});- it.slow()('should close the browser when the node process closes', async ({browserType}) => {- const result = await testSignal(browserType, child => {+ it.slow()('should close the browser when the node process closes', async state => {+ const result = await testSignal(state, child => {if (WIN)execSync(`taskkill /pid ${child.pid} /T /F`);else@@ -84,38 +84,38 @@ describe('Fixtures', function() {describe.skip(WIN)('signals', () => {// Cannot reliably send signals on Windows.- it.slow()('should report browser close signal', async ({browserType}) => {- const result = await testSignal(browserType, (child, browserPid) => process.kill(browserPid), true);+ it.slow()('should report browser close signal', async state => {+ const result = await testSignal(state, (child, browserPid) => process.kill(browserPid), true);expect(result.exitCode).toBe(0);expect(result.browserExitCode).toBe('null');expect(result.browserSignal).toBe('SIGTERM');});- it.slow()('should report browser close signal 2', async ({browserType}) => {- const result = await testSignal(browserType, (child, browserPid) => process.kill(browserPid, 'SIGKILL'), true);+ it.slow()('should report browser close signal 2', async state => {+ const result = await testSignal(state, (child, browserPid) => process.kill(browserPid, 'SIGKILL'), true);expect(result.exitCode).toBe(0);expect(result.browserExitCode).toBe('null');expect(result.browserSignal).toBe('SIGKILL');});- it.slow()('should close the browser on SIGINT', async ({browserType}) => {- const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGINT'));+ it.slow()('should close the browser on SIGINT', async state => {+ const result = await testSignal(state, child => process.kill(child.pid, 'SIGINT'));expect(result.exitCode).toBe(130);expect(result.browserExitCode).toBe('0');expect(result.browserSignal).toBe('null');});- it.slow()('should close the browser on SIGTERM', async ({browserType}) => {- const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGTERM'));+ it.slow()('should close the browser on SIGTERM', async state => {+ const result = await testSignal(state, child => process.kill(child.pid, 'SIGTERM'));expect(result.exitCode).toBe(0);expect(result.browserExitCode).toBe('0');expect(result.browserSignal).toBe('null');});- it.slow()('should close the browser on SIGHUP', async ({browserType}) => {- const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGHUP'));+ it.slow()('should close the browser on SIGHUP', async state => {+ const result = await testSignal(state, child => process.kill(child.pid, 'SIGHUP'));expect(result.exitCode).toBe(0);expect(result.browserExitCode).toBe('0');expect(result.browserSignal).toBe('null');});- it.slow()('should kill the browser on double SIGINT', async ({browserType}) => {- const result = await testSignal(browserType, child => {+ it.slow()('should kill the browser on double SIGINT', async state => {+ const result = await testSignal(state, child => {process.kill(child.pid, 'SIGINT');process.kill(child.pid, 'SIGINT');});@@ -123,8 +123,8 @@ describe('Fixtures', function() {// TODO: ideally, we would expect the SIGKILL on the browser from// force kill, but that's racy with sending two signals.});- it.slow()('should kill the browser on SIGINT + SIGTERM', async ({browserType}) => {- const result = await testSignal(browserType, child => {+ it.slow()('should kill the browser on SIGINT + SIGTERM', async state => {+ const result = await testSignal(state, child => {process.kill(child.pid, 'SIGINT');process.kill(child.pid, 'SIGTERM');});@@ -132,8 +132,8 @@ describe('Fixtures', function() {// TODO: ideally, we would expect the SIGKILL on the browser from// force kill, but that's racy with sending two signals.});- it.slow()('should kill the browser on SIGTERM + SIGINT', async ({browserType}) => {- const result = await testSignal(browserType, child => {+ it.slow()('should kill the browser on SIGTERM + SIGINT', async state => {+ const result = await testSignal(state, child => {process.kill(child.pid, 'SIGTERM');process.kill(child.pid, 'SIGINT');});diff --git a/test/headful.spec.js b/test/headful.spec.jsindex 146fdb38ff..5de81b66fa 100644--- a/test/headful.spec.js+++ b/test/headful.spec.js@@ -16,35 +16,28 @@const utils = require('./utils');const { makeUserDataDir, removeUserDataDir } = utils;-const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions} = utils.testOptions(browserType);--const headfulOptions = Object.assign({}, defaultBrowserOptions, {- headless: false-});-const headlessOptions = Object.assign({}, defaultBrowserOptions, {- headless: true-});+const {FFOX, CHROMIUM, WEBKIT, WIN} = utils.testOptions(browserType);describe('Headful', function() {- it('should have default url when launching browser', async ({browserType}) => {+ it('should have default url when launching browser', async ({browserType, defaultBrowserOptions}) => {const userDataDir = await makeUserDataDir();- const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions);+ const browserContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false });const urls = browserContext.pages().map(page => page.url());expect(urls).toEqual(['about:blank']);await browserContext.close();await removeUserDataDir(userDataDir);});- it.slow().fail(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({browserType, server}) => {+ it.slow().fail(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({browserType, defaultBrowserOptions, server}) => {// see https://github.com/microsoft/playwright/issues/717const userDataDir = await makeUserDataDir();// Write a cookie in headful chrome- const headfulContext = await browserType.launchPersistentContext(userDataDir, headfulOptions);+ const headfulContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false});const headfulPage = await headfulContext.newPage();await headfulPage.goto(server.EMPTY_PAGE);await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');await headfulContext.close();// Read the cookie from headless chrome- const headlessContext = await browserType.launchPersistentContext(userDataDir, headlessOptions);+ const headlessContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: true});const headlessPage = await headlessContext.newPage();await headlessPage.goto(server.EMPTY_PAGE);const cookie = await headlessPage.evaluate(() => document.cookie);@@ -53,9 +46,9 @@ describe('Headful', function() {await removeUserDataDir(userDataDir);expect(cookie).toBe('foo=true');});- it.slow()('should close browser with beforeunload page', async({browserType, server}) => {+ it.slow()('should close browser with beforeunload page', async({browserType, defaultBrowserOptions, server}) => {const userDataDir = await makeUserDataDir();- const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions);+ const browserContext = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, headless: false});const page = await browserContext.newPage();await page.goto(server.PREFIX + '/beforeunload.html');// We have to interact with a page so that 'beforeunload' handlersdiff --git a/test/launcher.spec.js b/test/launcher.spec.jsindex b8623c5990..a144264286 100644--- a/test/launcher.spec.js+++ b/test/launcher.spec.js@@ -19,11 +19,11 @@ const path = require('path');const fs = require('fs');const utils = require('./utils');const { makeUserDataDir, removeUserDataDir } = utils;-const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions, playwrightPath} = utils.testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT, WIN} = utils.testOptions(browserType);describe('Playwright', function() {describe('browserType.launch', function() {- it('should reject all promises when browser is closed', async({browserType}) => {+ it('should reject all promises when browser is closed', async({browserType, defaultBrowserOptions}) => {const browser = await browserType.launch(defaultBrowserOptions);const page = await (await browser.newContext()).newPage();let error = null;@@ -32,19 +32,19 @@ describe('Playwright', function() {await neverResolves;expect(error.message).toContain('Protocol error');});- it('should throw if userDataDir option is passed', async({browserType}) => {+ it('should throw if userDataDir option is passed', async({browserType, defaultBrowserOptions}) => {let waitError = null;const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});await browserType.launch(options).catch(e => waitError = e);expect(waitError.message).toContain('launchPersistentContext');});- it('should throw if page argument is passed', async({browserType}) => {+ it('should throw if page argument is passed', async({browserType, defaultBrowserOptions}) => {let waitError = null;const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] });await browserType.launch(options).catch(e => waitError = e);expect(waitError.message).toContain('can not specify page');});- it('should reject if executable path is invalid', async({browserType}) => {+ it('should reject if executable path is invalid', async({browserType, defaultBrowserOptions}) => {let waitError = null;const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});await browserType.launch(options).catch(e => waitError = e);@@ -53,7 +53,7 @@ describe('Playwright', function() {});describe('browserType.launchPersistentContext', function() {- it('should have default URL when launching browser', async ({browserType}) => {+ it('should have default URL when launching browser', async ({browserType, defaultBrowserOptions}) => {const userDataDir = await makeUserDataDir();const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);const urls = browserContext.pages().map(page => page.url());@@ -61,7 +61,7 @@ describe('Playwright', function() {await browserContext.close();await removeUserDataDir(userDataDir);});- it('should have custom URL when launching browser', async ({browserType, server}) => {+ it('should have custom URL when launching browser', async ({browserType, defaultBrowserOptions, server}) => {const userDataDir = await makeUserDataDir();const options = Object.assign({}, defaultBrowserOptions);options.args = [server.EMPTY_PAGE].concat(options.args || []);@@ -79,12 +79,12 @@ describe('Playwright', function() {});describe('browserType.launchServer', function() {- it('should return child_process instance', async ({browserType}) => {+ it('should return child_process instance', async ({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);expect(browserServer.process().pid).toBeGreaterThan(0);await browserServer.close();});- it('should fire close event', async ({browserType}) => {+ it('should fire close event', async ({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);await Promise.all([new Promise(f => browserServer.on('close', f)),@@ -124,13 +124,12 @@ describe('Top-level requires', function() {const Devices = require(path.join(utils.projectRoot(), '/lib/deviceDescriptors.js')).DeviceDescriptors;expect(Devices['iPhone 6']).toBeTruthy();expect(Devices['iPhone 6']).toBe(playwright.devices['iPhone 6']);- expect(Devices['iPhone 6']).toBe(require(playwrightPath).devices['iPhone 6']);});});describe('Browser.isConnected', () => {- it('should set the browser connected state', async ({browserType}) => {- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ it('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => {+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });expect(remote.isConnected()).toBe(true);await remote.close();@@ -138,8 +137,8 @@ describe('Browser.isConnected', () => {await browserServer._checkLeaks();await browserServer.close();});- it('should throw when used after isConnected returns false', async({browserType}) => {- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ it('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => {+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const page = await remote.newPage();await Promise.all([@@ -153,9 +152,9 @@ describe('Browser.isConnected', () => {});describe('Browser.disconnect', function() {- it('should reject navigation when browser closes', async({browserType, server}) => {+ it('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => {server.setRoute('/one-style.css', () => {});- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const page = await remote.newPage();const navigationPromise = page.goto(server.PREFIX + '/one-style.html', {timeout: 60000}).catch(e => e);@@ -166,9 +165,9 @@ describe('Browser.disconnect', function() {await browserServer._checkLeaks();await browserServer.close();});- it('should reject waitForSelector when browser closes', async({browserType, server}) => {+ it('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => {server.setRoute('/empty.html', () => {});- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const page = await remote.newPage();const watchdog = page.waitForSelector('div', { timeout: 60000 }).catch(e => e);@@ -182,8 +181,8 @@ describe('Browser.disconnect', function() {await browserServer._checkLeaks();await browserServer.close();});- it('should throw if used after disconnect', async({browserType}) => {- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ it('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => {+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const page = await remote.newPage();await remote.close();@@ -192,8 +191,8 @@ describe('Browser.disconnect', function() {await browserServer._checkLeaks();await browserServer.close();});- it('should emit close events on pages and contexts', async({browserType}) => {- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ it('should emit close events on pages and contexts', async({browserType, defaultBrowserOptions}) => {+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const context = await remote.newContext();const page = await context.newPage();@@ -208,8 +207,8 @@ describe('Browser.disconnect', function() {});describe('Browser.close', function() {- it('should terminate network waiters', async({browserType, server}) => {- const browserServer = await browserType.launchServer({...defaultBrowserOptions });+ it('should terminate network waiters', async({browserType, defaultBrowserOptions, server}) => {+ const browserServer = await browserType.launchServer(defaultBrowserOptions);const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const newPage = await remote.newPage();const results = await Promise.all([@@ -223,7 +222,7 @@ describe('Browser.close', function() {expect(message).not.toContain('Timeout');}});- it('should fire close event for all contexts', async({browserType}) => {+ it('should fire close event for all contexts', async({browserType, defaultBrowserOptions}) => {const browser = await browserType.launch(defaultBrowserOptions);const context = await browser.newContext();let closed = false;@@ -234,7 +233,7 @@ describe('Browser.close', function() {});describe('browserType.launch |webSocket| option', function() {- it('should support the webSocket option', async({browserType}) => {+ it('should support the webSocket option', async({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const browserContext = await browser.newContext();@@ -247,7 +246,7 @@ describe('browserType.launch |webSocket| option', function() {await browserServer._checkLeaks();await browserServer.close();});- it('should fire "disconnected" when closing with webSocket', async({browserType}) => {+ it('should fire "disconnected" when closing with webSocket', async({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));@@ -261,7 +260,7 @@ describe('browserType.launch |webSocket| option', function() {});describe('browserType.connect', function() {- it.slow()('should be able to reconnect to a browser', async({browserType, server}) => {+ it.slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);{const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });@@ -283,10 +282,9 @@ describe('browserType.connect', function() {});describe('browserType.launchPersistentContext', function() {- it('userDataDir option', async({browserType}) => {+ it('userDataDir option', async({browserType, defaultBrowserOptions}) => {const userDataDir = await makeUserDataDir();- const options = Object.assign(defaultBrowserOptions);- const browserContext = await browserType.launchPersistentContext(userDataDir, options);+ const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);// Open a page to make sure its functional.await browserContext.newPage();expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);@@ -295,7 +293,7 @@ describe('browserType.launchPersistentContext', function() {// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778await removeUserDataDir(userDataDir);});- it.slow()('userDataDir option should restore state', async({browserType, server}) => {+ it.slow()('userDataDir option should restore state', async({browserType, defaultBrowserOptions, server}) => {const userDataDir = await makeUserDataDir();const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);const page = await browserContext.newPage();@@ -320,7 +318,7 @@ describe('browserType.launchPersistentContext', function() {await removeUserDataDir(userDataDir);await removeUserDataDir(userDataDir2);});- it.slow()('userDataDir option should restore cookies', async({browserType, server}) => {+ it.slow()('userDataDir option should restore cookies', async({browserType, defaultBrowserOptions, server}) => {const userDataDir = await makeUserDataDir();const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);const page = await browserContext.newPage();diff --git a/test/multiclient.spec.js b/test/multiclient.spec.jsindex 18cba582b8..ada95477fc 100644--- a/test/multiclient.spec.js+++ b/test/multiclient.spec.js@@ -15,10 +15,10 @@* limitations under the License.*/-const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('./utils').testOptions(browserType);+const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);describe('BrowserContext', function() {- it('should work across sessions', async ({browserType}) => {+ it('should work across sessions', async ({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });expect(browser1.contexts().length).toBe(0);@@ -41,7 +41,7 @@ describe('BrowserContext', function() {});describe('Browser.Events.disconnected', function() {- it.slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async ({browserType}) => {+ it.slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async ({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);const originalBrowser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const wsEndpoint = browserServer.wsEndpoint();@@ -77,7 +77,7 @@ describe('Browser.Events.disconnected', function() {});describe('browserType.connect', function() {- it('should be able to connect multiple times to the same browser', async({browserType}) => {+ it('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });@@ -91,7 +91,7 @@ describe('browserType.connect', function() {await browserServer._checkLeaks();await browserServer.close();});- it('should not be able to close remote browser', async({browserType}) => {+ it('should not be able to close remote browser', async({browserType, defaultBrowserOptions}) => {const browserServer = await browserType.launchServer(defaultBrowserOptions);{const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });diff --git a/test/test.config.js b/test/test.config.jsindex 1df9963f47..e9a35c4b17 100644--- a/test/test.config.js+++ b/test/test.config.js@@ -21,6 +21,8 @@ const rm = require('rimraf').sync;const {TestServer} = require('../utils/testserver/');const {Environment} = require('../utils/testrunner/Test');+const playwrightPath = path.join(__dirname, '..');+const serverEnvironment = new Environment('TestServer');serverEnvironment.beforeAll(async state => {const assetsPath = path.join(__dirname, 'assets');@@ -41,6 +43,13 @@ serverEnvironment.beforeAll(async state => {state.httpsServer.PREFIX = `https://localhost:${httpsPort}`;state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`;state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`;++ state.defaultBrowserOptions = {+ handleSIGINT: false,+ slowMo: valueFromEnv('SLOW_MO', 0),+ headless: !!valueFromEnv('HEADLESS', true),+ };+ state.playwrightPath = playwrightPath;});serverEnvironment.afterAll(async({server, httpsServer}) => {await Promise.all([@@ -123,7 +132,7 @@ function setupTestRunner(testRunner) {}module.exports = {- playwrightPath: '..',+ playwrightPath,dumpProtocolOnFailure: valueFromEnv('DEBUGP', false),launchOptions: {executablePath: {diff --git a/test/utils.js b/test/utils.jsindex 277be1236d..961af67397 100644--- a/test/utils.js+++ b/test/utils.js@@ -172,12 +172,6 @@ const utils = module.exports = {},testOptions(browserType) {- const headless = !!valueFromEnv('HEADLESS', true);- const defaultBrowserOptions = {- handleSIGINT: false,- slowMo: valueFromEnv('SLOW_MO', 0),- headless,- };const GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name());const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());return {@@ -188,9 +182,6 @@ const utils = module.exports = {LINUX: platform === 'linux',WIN: platform === 'win32',browserType,- defaultBrowserOptions,- playwrightPath: PROJECT_ROOT,- headless,GOLDEN_DIR,OUTPUT_DIR,};