Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: move most launcher tests to common (#621)

Dmitry Gozman2b44d75eb6b2
diff --git a/test/browser.spec.js b/test/browser.spec.js
deleted file mode 100644
index 4fd02de855..0000000000
--- a/test/browser.spec.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright 2018 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-module.exports.describe = function({testRunner, expect, headless, playwright, FFOX, CHROMIUM, WEBKIT}) {
- const {describe, xdescribe, fdescribe} = testRunner;
- const {it, fit, xit, dit} = testRunner;
- const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
-
- describe('Browser.process', function() {
- it('should return child_process instance', async function({browserApp}) {
- const process = await browserApp.process();
- expect(process.pid).toBeGreaterThan(0);
- });
- });
-};
diff --git a/test/chromium/browser.spec.js b/test/chromium/browser.spec.js
deleted file mode 100644
index 343a6bde28..0000000000
--- a/test/chromium/browser.spec.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-const path = require('path');
-const {spawn, execSync} = require('child_process');
-
-module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, product}) {
- const {describe, xdescribe, fdescribe} = testRunner;
- const {it, fit, xit, dit} = testRunner;
- const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
-
- describe('CRBrowser', function() {
- it('should close all belonging targets once closing context', async function({browser, newContext}) {
- const targets = async () => (await browser.targets()).filter(t => t.type() === 'page');
- expect((await targets()).length).toBe(1);
-
- const context = await newContext();
- await context.newPage();
- expect((await targets()).length).toBe(2);
- expect((await context.pages()).length).toBe(1);
-
- await context.close();
- expect((await targets()).length).toBe(1);
- });
- it('should close the browser when the node process closes', async({ server }) => {
- const options = Object.assign({}, defaultBrowserOptions, {
- // Disable DUMPIO to cleanly read stdout.
- dumpio: false,
- webSocket: true,
- });
- const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
- let wsEndPointCallback;
- const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
- let output = '';
- res.stdout.on('data', data => {
- output += data;
- if (output.indexOf('\n'))
- wsEndPointCallback(output.substring(0, output.indexOf('\n')));
- });
- const browser = await playwright.connect({ browserWSEndpoint: await wsEndPointPromise });
- const promises = [
- new Promise(resolve => browser.once('disconnected', resolve)),
- new Promise(resolve => res.on('exit', resolve))
- ];
- if (process.platform === 'win32')
- execSync(`taskkill /pid ${res.pid} /T /F`);
- else
- process.kill(res.pid);
- await Promise.all(promises);
- });
- });
-};
diff --git a/test/chromium/chromium.spec.js b/test/chromium/chromium.spec.js
index aa66628de3..e6c5a3c2fc 100644
--- a/test/chromium/chromium.spec.js
+++ b/test/chromium/chromium.spec.js
@@ -155,6 +155,19 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
expect(createdTarget.opener()).toBe(browser.pageTarget(page));
expect(browser.pageTarget(page).opener()).toBe(null);
});
+ it('should close all belonging targets once closing context', async function({browser, newContext}) {
+ const targets = async () => (await browser.targets()).filter(t => t.type() === 'page');
+ // There is one page in a default profile and one page created by test harness.
+ expect((await targets()).length).toBe(2);
+
+ const context = await newContext();
+ await context.newPage();
+ expect((await targets()).length).toBe(3);
+ expect((await context.pages()).length).toBe(1);
+
+ await context.close();
+ expect((await targets()).length).toBe(2);
+ });
});
describe('Chromium.waitForTarget', () => {
diff --git a/test/chromium/launcher.spec.js b/test/chromium/launcher.spec.js
index 654de57aec..e6d7cede93 100644
--- a/test/chromium/launcher.spec.js
+++ b/test/chromium/launcher.spec.js
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-const { waitEvent } = require('../utils');
const util = require('util');
const fs = require('fs');
const path = require('path');
@@ -32,19 +31,6 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('CrPlaywright', function() {
- describe('BrowserContext', function() {
- it('should work across sessions', async () => {
- const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
- const browser = await playwright.connect(browserApp.connectOptions());
- expect(browser.browserContexts().length).toBe(1);
- await browser.newContext();
- expect(browser.browserContexts().length).toBe(2);
- const remoteBrowser = await playwright.connect(browserApp.connectOptions());
- const contexts = remoteBrowser.browserContexts();
- expect(contexts.length).toBe(2);
- await browserApp.close();
- });
- });
describe('Playwright.launch |browserURL| option', function() {
function getBrowserUrl(wsEndpoint) {
const port = wsEndpoint.match(/ws:\/\/([0-9A-Za-z\.]*):(\d+)\//)[2];
@@ -134,42 +120,6 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
});
});
- describe('Browser.Events.disconnected', function() {
- it('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async() => {
- const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
- const originalBrowser = await playwright.connect(browserApp.connectOptions());
- const browserWSEndpoint = browserApp.wsEndpoint();
- const remoteBrowser1 = await playwright.connect({browserWSEndpoint});
- const remoteBrowser2 = await playwright.connect({browserWSEndpoint});
-
- let disconnectedOriginal = 0;
- let disconnectedRemote1 = 0;
- let disconnectedRemote2 = 0;
- originalBrowser.on('disconnected', () => ++disconnectedOriginal);
- remoteBrowser1.on('disconnected', () => ++disconnectedRemote1);
- remoteBrowser2.on('disconnected', () => ++disconnectedRemote2);
-
- await Promise.all([
- waitEvent(remoteBrowser2, 'disconnected'),
- remoteBrowser2.disconnect(),
- ]);
-
- expect(disconnectedOriginal).toBe(0);
- expect(disconnectedRemote1).toBe(0);
- expect(disconnectedRemote2).toBe(1);
-
- await Promise.all([
- waitEvent(remoteBrowser1, 'disconnected'),
- waitEvent(originalBrowser, 'disconnected'),
- browserApp.close(),
- ]);
-
- expect(disconnectedOriginal).toBe(1);
- expect(disconnectedRemote1).toBe(1);
- expect(disconnectedRemote2).toBe(1);
- });
- });
-
describe('BrowserFetcher', function() {
it('should download and extract linux binary', async({server}) => {
const downloadsFolder = await mkdtempAsync(TMP_FOLDER);
diff --git a/test/firefox/browser.spec.js b/test/firefox/browser.spec.js
deleted file mode 100644
index 82c4ae75f2..0000000000
--- a/test/firefox/browser.spec.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-const path = require('path');
-const {spawn, execSync} = require('child_process');
-
-module.exports.describe = function({testRunner, defaultBrowserOptions, playwright, playwrightPath, product}) {
- const {describe, xdescribe, fdescribe} = testRunner;
- const {it, fit, xit, dit} = testRunner;
- const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
-
- describe('FFBrowser', function() {
- it('should close the browser when the node process closes', async({ server }) => {
- const options = Object.assign({}, defaultBrowserOptions, {
- // Disable DUMPIO to cleanly read stdout.
- dumpio: false,
- webSocket: true,
- });
- const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
- let wsEndPointCallback;
- const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
- let output = '';
- res.stdout.on('data', data => {
- output += data;
- if (output.indexOf('\n') !== -1)
- wsEndPointCallback(output.substring(0, output.indexOf('\n')));
- });
- const browser = await playwright.connect({ browserWSEndpoint: await wsEndPointPromise });
- const promises = [
- new Promise(resolve => browser.once('disconnected', resolve)),
- new Promise(resolve => res.on('exit', resolve))
- ];
- if (process.platform === 'win32')
- execSync(`taskkill /pid ${res.pid} /T /F`);
- else
- process.kill(res.pid);
- await Promise.all(promises);
- });
- });
-};
diff --git a/test/firefox/launcher.spec.js b/test/firefox/launcher.spec.js
deleted file mode 100644
index 2f38df5459..0000000000
--- a/test/firefox/launcher.spec.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright 2017 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-const fs = require('fs');
-const os = require('os');
-const path = require('path');
-const utils = require('../utils');
-const rmAsync = utils.promisify(require('rimraf'));
-const mkdtempAsync = utils.promisify(fs.mkdtemp);
-const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
-
-module.exports.describe = function ({ testRunner, expect, defaultBrowserOptions, playwright }) {
- const {describe, xdescribe, fdescribe} = testRunner;
- const {it, fit, xit, dit} = testRunner;
- const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
-
- describe('FFPlaywright', function() {
- describe('Playwright.launch', function() {
- it('userDataDir option', async({server}) => {
- const userDataDir = await mkdtempAsync(TMP_FOLDER);
- const options = Object.assign({userDataDir}, defaultBrowserOptions);
- const browser = await playwright.launch(options);
- // Open a page to make sure its functional.
- await browser.defaultContext().newPage();
- expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
- await browser.close();
- expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
- // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
- await rmAsync(userDataDir).catch(e => {});
- });
- it('userDataDir argument', async({server}) => {
- const userDataDir = await mkdtempAsync(TMP_FOLDER);
- const options = Object.assign({}, defaultBrowserOptions);
- options.args = [
- ...(defaultBrowserOptions.args || []),
- `-profile`,
- userDataDir,
- ];
- const browser = await playwright.launch(options);
- expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
- await browser.close();
- expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
- // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
- await rmAsync(userDataDir).catch(e => {});
- });
- it('should return the default arguments', async() => {
- expect(playwright.defaultArgs({browser: 'firefox'})).toContain('-headless');
- expect(playwright.defaultArgs({browser: 'firefox', headless: false})).not.toContain('-headless');
- expect(playwright.defaultArgs({browser: 'firefox', userDataDir: 'foo'})).toContain('-profile');
- expect(playwright.defaultArgs({browser: 'firefox', userDataDir: 'foo'})).toContain('foo');
- });
- it('should filter out ignored default arguments', async() => {
- // Make sure we launch with `--enable-automation` by default.
- const defaultArgs = playwright.defaultArgs(defaultBrowserOptions);
- const browserApp = await playwright.launchBrowserApp(Object.assign({}, defaultBrowserOptions, {
- // Ignore first and third default argument.
- ignoreDefaultArgs: [ defaultArgs[0], defaultArgs[2] ],
- }));
- const spawnargs = browserApp.process().spawnargs;
- expect(spawnargs.indexOf(defaultArgs[0])).toBe(-1);
- expect(spawnargs.indexOf(defaultArgs[1])).not.toBe(-1);
- expect(spawnargs.indexOf(defaultArgs[2])).toBe(-1);
- await browserApp.close();
- });
- });
- });
-};
diff --git a/test/launcher.spec.js b/test/launcher.spec.js
index 2596de6491..b34fd27fb3 100644
--- a/test/launcher.spec.js
+++ b/test/launcher.spec.js
@@ -18,6 +18,7 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const util = require('util');
+const {spawn, execSync} = require('child_process');
const utils = require('./utils');
const rmAsync = util.promisify(require('rimraf'));
@@ -25,7 +26,7 @@ const mkdtempAsync = util.promisify(fs.mkdtemp);
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
-module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, CHROMIUM, FFOX, WEBKIT}) {
+module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, product, CHROMIUM, FFOX, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
@@ -66,6 +67,37 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
expect(page.url()).toBe(server.EMPTY_PAGE);
await browser.close();
});
+ it('should close the browser when the node process closes', async({ server }) => {
+ const options = Object.assign({}, defaultBrowserOptions, {
+ // Disable DUMPIO to cleanly read stdout.
+ dumpio: false,
+ webSocket: true,
+ });
+ const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
+ let wsEndPointCallback;
+ const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
+ let output = '';
+ res.stdout.on('data', data => {
+ output += data;
+ if (output.indexOf('\n'))
+ wsEndPointCallback(output.substring(0, output.indexOf('\n')));
+ });
+ const browser = await playwright.connect({ browserWSEndpoint: await wsEndPointPromise });
+ const promises = [
+ new Promise(resolve => browser.once('disconnected', resolve)),
+ new Promise(resolve => res.on('exit', resolve))
+ ];
+ if (process.platform === 'win32')
+ execSync(`taskkill /pid ${res.pid} /T /F`);
+ else
+ process.kill(res.pid);
+ await Promise.all(promises);
+ });
+ it('should return child_process instance', async () => {
+ const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
+ expect(browserApp.process().pid).toBeGreaterThan(0);
+ await browserApp.close();
+ });
});
describe('Playwright.executablePath', function() {
@@ -75,6 +107,28 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
expect(fs.realpathSync(executablePath)).toBe(executablePath);
});
});
+
+ describe('Playwright.defaultArguments', () => {
+ it('should return the default arguments', async() => {
+ if (CHROMIUM)
+ expect(playwright.defaultArgs()).toContain('--no-first-run');
+ expect(playwright.defaultArgs()).toContain(FFOX ? '-headless' : '--headless');
+ expect(playwright.defaultArgs({headless: false})).not.toContain(FFOX ? '-headless' : '--headless');
+ expect(playwright.defaultArgs({userDataDir: 'foo'})).toContain(FFOX ? 'foo' : '--user-data-dir=foo');
+ });
+ it('should filter out ignored default arguments', async() => {
+ // Make sure we launch with `--enable-automation` by default.
+ const defaultArgs = playwright.defaultArgs(defaultBrowserOptions);
+ const browserApp = await playwright.launchBrowserApp(Object.assign({}, defaultBrowserOptions, {
+ // Ignore second default argument.
+ ignoreDefaultArgs: [ defaultArgs[1] ],
+ }));
+ const spawnargs = browserApp.process().spawnargs;
+ expect(spawnargs.indexOf(defaultArgs[0])).not.toBe(-1);
+ expect(spawnargs.indexOf(defaultArgs[1])).toBe(-1);
+ await browserApp.close();
+ });
+ });
});
describe('Top-level requires', function() {
@@ -228,7 +282,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
});
});
- describe.skip(FFOX || WEBKIT)('Playwright.launch({userDataDir})', function() {
+ describe.skip(WEBKIT)('Playwright.launch({userDataDir})', function() {
it('userDataDir option', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
@@ -244,10 +298,11 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
it('userDataDir argument', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({}, defaultBrowserOptions);
- options.args = [
- ...(defaultBrowserOptions.args || []),
- `--user-data-dir=${userDataDir}`
- ];
+ options.args = [...(defaultBrowserOptions.args || [])];
+ if (FFOX)
+ options.args.push('-profile', userDataDir);
+ else
+ options.args.push(`--user-data-dir=${userDataDir}`);
const browser = await playwright.launch(options);
// Open a page to make sure its functional.
await browser.defaultContext().newPage();
@@ -257,27 +312,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await rmAsync(userDataDir).catch(e => {});
});
- it('should return the default arguments', async() => {
- if (CHROMIUM)
- expect(playwright.defaultArgs()).toContain('--no-first-run');
- expect(playwright.defaultArgs()).toContain('--headless');
- expect(playwright.defaultArgs({headless: false})).not.toContain('--headless');
- expect(playwright.defaultArgs({userDataDir: 'foo'})).toContain('--user-data-dir=foo');
- });
- it('should filter out ignored default arguments', async() => {
- // Make sure we launch with `--enable-automation` by default.
- const defaultArgs = playwright.defaultArgs(defaultBrowserOptions);
- const browserApp = await playwright.launchBrowserApp(Object.assign({}, defaultBrowserOptions, {
- // Ignore first and third default argument.
- ignoreDefaultArgs: [ defaultArgs[0], defaultArgs[2] ],
- }));
- const spawnargs = browserApp.process().spawnargs;
- expect(spawnargs.indexOf(defaultArgs[0])).toBe(-1);
- expect(spawnargs.indexOf(defaultArgs[1])).not.toBe(-1);
- expect(spawnargs.indexOf(defaultArgs[2])).toBe(-1);
- await browserApp.close();
- });
- it('userDataDir option should restore state', async({server}) => {
+ it.skip(FFOX)('userDataDir option should restore state', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
@@ -302,7 +337,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await rmAsync(userDataDir).catch(e => {});
});
// This mysteriously fails on Windows on AppVeyor. See https://github.com/GoogleChrome/puppeteer/issues/4111
- it('userDataDir option should restore cookies', async({server}) => {
+ it.skip(FFOX)('userDataDir option should restore cookies', async({server}) => {
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
const browser = await playwright.launch(options);
diff --git a/test/chromium/connect.spec.js b/test/multiclient.spec.js
similarity index 55%
rename from test/chromium/connect.spec.js
rename to test/multiclient.spec.js
index 5076fd34fd..a7c8f5ceb7 100644
--- a/test/chromium/connect.spec.js
+++ b/test/multiclient.spec.js
@@ -15,13 +15,63 @@
* limitations under the License.
*/
-const utils = require('../utils');
+const utils = require('./utils');
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, dit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
+ describe('BrowserContext', function() {
+ it('should work across sessions', async () => {
+ const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
+ const browser = await playwright.connect(browserApp.connectOptions());
+ expect(browser.browserContexts().length).toBe(1);
+ await browser.newContext();
+ expect(browser.browserContexts().length).toBe(2);
+ const remoteBrowser = await playwright.connect(browserApp.connectOptions());
+ const contexts = remoteBrowser.browserContexts();
+ expect(contexts.length).toBe(2);
+ await browserApp.close();
+ });
+ });
+
+ describe('Browser.Events.disconnected', function() {
+ it('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async() => {
+ const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
+ const originalBrowser = await playwright.connect(browserApp.connectOptions());
+ const browserWSEndpoint = browserApp.wsEndpoint();
+ const remoteBrowser1 = await playwright.connect({browserWSEndpoint});
+ const remoteBrowser2 = await playwright.connect({browserWSEndpoint});
+
+ let disconnectedOriginal = 0;
+ let disconnectedRemote1 = 0;
+ let disconnectedRemote2 = 0;
+ originalBrowser.on('disconnected', () => ++disconnectedOriginal);
+ remoteBrowser1.on('disconnected', () => ++disconnectedRemote1);
+ remoteBrowser2.on('disconnected', () => ++disconnectedRemote2);
+
+ await Promise.all([
+ utils.waitEvent(remoteBrowser2, 'disconnected'),
+ remoteBrowser2.disconnect(),
+ ]);
+
+ expect(disconnectedOriginal).toBe(0);
+ expect(disconnectedRemote1).toBe(0);
+ expect(disconnectedRemote2).toBe(1);
+
+ await Promise.all([
+ utils.waitEvent(remoteBrowser1, 'disconnected'),
+ utils.waitEvent(originalBrowser, 'disconnected'),
+ browserApp.close(),
+ ]);
+
+ expect(disconnectedOriginal).toBe(1);
+ expect(disconnectedRemote1).toBe(1);
+ expect(disconnectedRemote2).toBe(1);
+ });
+ });
+
describe('Playwright.connect', function() {
it('should be able to connect multiple times to the same browser', async({server}) => {
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
@@ -58,15 +108,14 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
// @see https://github.com/GoogleChrome/puppeteer/issues/4197#issuecomment-481793410
it('should be able to connect to the same page simultaneously', async({server}) => {
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
- const local = await playwright.connect(browserApp.connectOptions());
- const remote = await playwright.connect(browserApp.connectOptions());
- const [page1, page2] = await Promise.all([
- new Promise(x => local.once('targetcreated', target => x(target.page()))),
- remote.defaultContext().newPage(),
- ]);
+ const browser1 = await playwright.connect(browserApp.connectOptions());
+ const page1 = await browser1.defaultContext().newPage();
+ await page1.goto(server.EMPTY_PAGE);
+ const browser2 = await playwright.connect(browserApp.connectOptions());
+ const page2 = (await browser2.defaultContext().pages()).find(page => page.url() === server.EMPTY_PAGE);
expect(await page1.evaluate(() => 7 * 8)).toBe(56);
expect(await page2.evaluate(() => 7 * 6)).toBe(42);
- await local.close();
+ await browserApp.close();
});
});
};
diff --git a/test/playwright.spec.js b/test/playwright.spec.js
index 460629c95e..d64138e39d 100644
--- a/test/playwright.spec.js
+++ b/test/playwright.spec.js
@@ -187,15 +187,8 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
});
// Browser-level tests that are given a browser.
- testRunner.loadTests(require('./browser.spec.js'), testOptions);
testRunner.loadTests(require('./browsercontext.spec.js'), testOptions);
testRunner.loadTests(require('./ignorehttpserrors.spec.js'), testOptions);
- if (CHROMIUM) {
- testRunner.loadTests(require('./chromium/browser.spec.js'), testOptions);
- }
- if (FFOX) {
- testRunner.loadTests(require('./firefox/browser.spec.js'), testOptions);
- }
});
// Top-level tests that launch Browser themselves.
@@ -204,19 +197,14 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
testRunner.loadTests(require('./launcher.spec.js'), testOptions);
if (CHROMIUM) {
- testRunner.loadTests(require('./chromium/connect.spec.js'), testOptions);
testRunner.loadTests(require('./chromium/launcher.spec.js'), testOptions);
testRunner.loadTests(require('./chromium/headful.spec.js'), testOptions);
testRunner.loadTests(require('./chromium/oopif.spec.js'), testOptions);
testRunner.loadTests(require('./chromium/tracing.spec.js'), testOptions);
}
- if (FFOX) {
- testRunner.loadTests(require('./firefox/launcher.spec.js'), testOptions);
- }
-
- if (WEBKIT) {
- testRunner.loadTests(require('./webkit/launcher.spec.js'), testOptions);
+ if (CHROMIUM || FFOX) {
+ testRunner.loadTests(require('./multiclient.spec.js'), testOptions);
}
testRunner.loadTests(require('./web.spec.js'), testOptions);
diff --git a/test/webkit/launcher.spec.js b/test/webkit/launcher.spec.js
deleted file mode 100644
index 6675f9ecfd..0000000000
--- a/test/webkit/launcher.spec.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright 2017 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-module.exports.describe = function ({ testRunner, expect, playwright, defaultBrowserOptions }) {
- const {describe, xdescribe, fdescribe} = testRunner;
- const {it, fit, xit, dit} = testRunner;
- const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
-
- describe('WKPlaywright', function() {
-
- });
-};