2019-12-10 14:02:48 -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.
|
|
|
|
*/
|
|
|
|
|
2020-01-22 17:42:10 -08:00
|
|
|
module.exports.describe = function ({ testRunner, expect, playwright, defaultBrowserOptions }) {
|
2019-12-10 14:02:48 -08:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
2019-12-19 15:47:35 -08:00
|
|
|
const {it, fit, xit, dit} = testRunner;
|
2019-12-10 14:02:48 -08:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
|
|
|
|
|
|
|
describe('WKPlaywright', function() {
|
|
|
|
describe('Playwright.launch', function() {
|
|
|
|
it('should return the default arguments', async() => {
|
|
|
|
expect(playwright.defaultArgs().length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
2020-01-22 17:42:10 -08:00
|
|
|
|
|
|
|
describe('Playwright.launch |pipe| option', function() {
|
|
|
|
it('should have websocket by default', async() => {
|
|
|
|
const options = Object.assign({pipe: false}, defaultBrowserOptions);
|
|
|
|
const browserServer = await playwright.launchServer(options);
|
2020-01-23 08:51:43 -08:00
|
|
|
const browser = await playwright.connect(browserServer.connectOptions());
|
2020-01-22 17:42:10 -08:00
|
|
|
expect((await browser.defaultContext().pages()).length).toBe(1);
|
|
|
|
expect(browserServer.wsEndpoint()).not.toBe(null);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
|
|
|
await page.close();
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
|
|
|
it('should support the pipe option', async() => {
|
|
|
|
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
|
|
|
const browserServer = await playwright.launchServer(options);
|
2020-01-23 08:51:43 -08:00
|
|
|
const browser = await playwright.connect(browserServer.connectOptions());
|
2020-01-22 17:42:10 -08:00
|
|
|
expect((await browser.defaultContext().pages()).length).toBe(1);
|
|
|
|
expect(browserServer.wsEndpoint()).toBe(null);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
|
|
|
await page.close();
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
|
|
|
it('should fire "disconnected" when closing with pipe', async() => {
|
|
|
|
const options = Object.assign({pipe: true}, defaultBrowserOptions);
|
|
|
|
const browserServer = await playwright.launchServer(options);
|
2020-01-23 08:51:43 -08:00
|
|
|
const browser = await playwright.connect(browserServer.connectOptions());
|
2020-01-22 17:42:10 -08:00
|
|
|
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
|
|
|
|
// Emulate user exiting browser.
|
|
|
|
process.kill(-browserServer.process().pid, 'SIGKILL');
|
|
|
|
await disconnectedEventPromise;
|
|
|
|
});
|
|
|
|
it('should fire "disconnected" when closing with websocket', async() => {
|
|
|
|
const options = Object.assign({pipe: false}, defaultBrowserOptions);
|
|
|
|
const browserServer = await playwright.launchServer(options);
|
2020-01-23 08:51:43 -08:00
|
|
|
const browser = await playwright.connect(browserServer.connectOptions());
|
2020-01-22 17:42:10 -08:00
|
|
|
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
|
|
|
|
// Emulate user exiting browser.
|
|
|
|
process.kill(-browserServer.process().pid, 'SIGKILL');
|
|
|
|
await disconnectedEventPromise;
|
|
|
|
});
|
|
|
|
});
|
2019-12-10 14:02:48 -08:00
|
|
|
});
|
|
|
|
};
|