2019-12-10 13:21:51 -08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-12-19 14:51:49 -08:00
|
|
|
|
2019-12-10 13:21:51 -08:00
|
|
|
const utils = require('../utils');
|
|
|
|
|
2020-01-13 10:13:28 -08:00
|
|
|
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
|
2019-12-10 13:21:51 -08:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
2019-12-19 15:47:35 -08:00
|
|
|
const {it, fit, xit, dit} = testRunner;
|
2019-12-10 13:21:51 -08:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
|
|
|
|
|
|
|
describe('Playwright.connect', function() {
|
|
|
|
it('should be able to connect multiple times to the same browser', async({server}) => {
|
2020-01-23 14:40:37 -08:00
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
const local = await playwright.connect(browserApp.connectOptions());
|
2019-12-19 14:51:49 -08:00
|
|
|
const remote = await playwright.connect({
|
2019-12-10 13:21:51 -08:00
|
|
|
...defaultBrowserOptions,
|
2020-01-23 14:40:37 -08:00
|
|
|
browserWSEndpoint: browserApp.wsEndpoint()
|
2019-12-10 13:21:51 -08:00
|
|
|
});
|
2019-12-19 14:51:49 -08:00
|
|
|
const page = await remote.defaultContext().newPage();
|
2019-12-10 13:21:51 -08:00
|
|
|
expect(await page.evaluate(() => 7 * 8)).toBe(56);
|
2019-12-19 14:51:49 -08:00
|
|
|
remote.disconnect();
|
2019-12-10 13:21:51 -08:00
|
|
|
|
2019-12-19 14:51:49 -08:00
|
|
|
const secondPage = await local.defaultContext().newPage();
|
2019-12-10 13:21:51 -08:00
|
|
|
expect(await secondPage.evaluate(() => 7 * 6)).toBe(42, 'original browser should still work');
|
2020-01-23 14:40:37 -08:00
|
|
|
await browserApp.close();
|
2019-12-10 13:21:51 -08:00
|
|
|
});
|
|
|
|
it('should be able to close remote browser', async({server}) => {
|
2020-01-23 14:40:37 -08:00
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
const local = await playwright.connect(browserApp.connectOptions());
|
2019-12-19 14:51:49 -08:00
|
|
|
const remote = await playwright.connect({
|
2019-12-10 13:21:51 -08:00
|
|
|
...defaultBrowserOptions,
|
2020-01-23 14:40:37 -08:00
|
|
|
browserWSEndpoint: browserApp.wsEndpoint()
|
2019-12-10 13:21:51 -08:00
|
|
|
});
|
|
|
|
await Promise.all([
|
2019-12-19 14:51:49 -08:00
|
|
|
utils.waitEvent(local, 'disconnected'),
|
|
|
|
remote.close(),
|
2019-12-10 13:21:51 -08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
// @see https://github.com/GoogleChrome/puppeteer/issues/4197#issuecomment-481793410
|
|
|
|
it('should be able to connect to the same page simultaneously', async({server}) => {
|
2020-01-23 14:40:37 -08:00
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
const local = await playwright.connect(browserApp.connectOptions());
|
|
|
|
const remote = await playwright.connect({ ...defaultBrowserOptions, browserWSEndpoint: browserApp.wsEndpoint() });
|
2019-12-10 13:21:51 -08:00
|
|
|
const [page1, page2] = await Promise.all([
|
2019-12-19 14:51:49 -08:00
|
|
|
new Promise(x => local.once('targetcreated', target => x(target.page()))),
|
|
|
|
remote.defaultContext().newPage(),
|
2019-12-10 13:21:51 -08:00
|
|
|
]);
|
|
|
|
expect(await page1.evaluate(() => 7 * 8)).toBe(56);
|
|
|
|
expect(await page2.evaluate(() => 7 * 6)).toBe(42);
|
2019-12-19 14:51:49 -08:00
|
|
|
await local.close();
|
2019-12-10 13:21:51 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|