2019-11-19 05:18:28 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
2019-12-11 00:21:51 +03:00
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
2019-11-19 05:18:28 +03:00
|
|
|
*
|
|
|
|
* 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');
|
2020-01-23 23:18:41 +03:00
|
|
|
const os = require('os');
|
2019-11-19 05:18:28 +03:00
|
|
|
const path = require('path');
|
2020-01-23 23:18:41 +03:00
|
|
|
const util = require('util');
|
|
|
|
|
2019-11-19 05:18:28 +03:00
|
|
|
const utils = require('./utils');
|
2020-01-23 23:18:41 +03:00
|
|
|
const rmAsync = util.promisify(require('rimraf'));
|
|
|
|
const mkdtempAsync = util.promisify(fs.mkdtemp);
|
|
|
|
|
2020-01-25 03:15:41 +03:00
|
|
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pw_tmp_folder-');
|
2019-11-19 05:18:28 +03:00
|
|
|
|
2020-01-29 05:04:51 +03:00
|
|
|
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, product, CHROMIUM, FFOX, WEBKIT, WIN}) {
|
2019-11-19 05:18:28 +03:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
2019-12-20 02:47:35 +03:00
|
|
|
const {it, fit, xit, dit} = testRunner;
|
2019-11-19 05:18:28 +03:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
|
|
|
|
|
|
|
describe('Playwright', function() {
|
2019-12-03 03:17:53 +03:00
|
|
|
describe('Playwright.launch', function() {
|
2019-11-19 05:18:28 +03:00
|
|
|
it('should reject all promises when browser is closed', async() => {
|
|
|
|
const browser = await playwright.launch(defaultBrowserOptions);
|
2019-12-19 05:07:11 +03:00
|
|
|
const page = await browser.defaultContext().newPage();
|
2019-11-19 05:18:28 +03:00
|
|
|
let error = null;
|
|
|
|
const neverResolves = page.evaluate(() => new Promise(r => {})).catch(e => error = e);
|
|
|
|
await browser.close();
|
|
|
|
await neverResolves;
|
|
|
|
expect(error.message).toContain('Protocol error');
|
|
|
|
});
|
|
|
|
it('should reject if executable path is invalid', async({server}) => {
|
|
|
|
let waitError = null;
|
|
|
|
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
|
|
|
|
await playwright.launch(options).catch(e => waitError = e);
|
|
|
|
expect(waitError.message).toContain('Failed to launch');
|
|
|
|
});
|
2019-12-11 01:02:48 +03:00
|
|
|
it('should have default URL when launching browser', async function() {
|
|
|
|
const browser = await playwright.launch(defaultBrowserOptions);
|
2019-12-19 05:07:11 +03:00
|
|
|
const pages = (await browser.defaultContext().pages()).map(page => page.url());
|
2019-12-11 01:02:48 +03:00
|
|
|
expect(pages).toEqual(['about:blank']);
|
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
it('should have custom URL when launching browser', async function({server}) {
|
|
|
|
const options = Object.assign({}, defaultBrowserOptions);
|
|
|
|
options.args = [server.EMPTY_PAGE].concat(options.args || []);
|
|
|
|
const browser = await playwright.launch(options);
|
2019-12-19 05:07:11 +03:00
|
|
|
const pages = await browser.defaultContext().pages();
|
2019-12-11 01:02:48 +03:00
|
|
|
expect(pages.length).toBe(1);
|
|
|
|
const page = pages[0];
|
2019-12-18 04:33:06 +03:00
|
|
|
if (page.url() !== server.EMPTY_PAGE) {
|
2019-12-11 01:02:48 +03:00
|
|
|
await page.waitForNavigation();
|
2019-12-18 04:33:06 +03:00
|
|
|
}
|
2019-12-11 01:02:48 +03:00
|
|
|
expect(page.url()).toBe(server.EMPTY_PAGE);
|
|
|
|
await browser.close();
|
|
|
|
});
|
2020-01-24 22:12:57 +03:00
|
|
|
it('should return child_process instance', async () => {
|
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
expect(browserApp.process().pid).toBeGreaterThan(0);
|
|
|
|
await browserApp.close();
|
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Playwright.executablePath', function() {
|
|
|
|
it('should work', async({server}) => {
|
|
|
|
const executablePath = playwright.executablePath();
|
|
|
|
expect(fs.existsSync(executablePath)).toBe(true);
|
|
|
|
expect(fs.realpathSync(executablePath)).toBe(executablePath);
|
|
|
|
});
|
|
|
|
});
|
2020-01-24 22:12:57 +03:00
|
|
|
|
2020-01-29 05:09:07 +03:00
|
|
|
describe('Playwright.name', function() {
|
|
|
|
it('should work', async({server}) => {
|
|
|
|
if (WEBKIT)
|
|
|
|
expect(playwright.name()).toBe('webkit');
|
|
|
|
else if (FFOX)
|
|
|
|
expect(playwright.name()).toBe('firefox');
|
|
|
|
else if (CHROMIUM)
|
|
|
|
expect(playwright.name()).toBe('chromium');
|
|
|
|
else
|
|
|
|
throw new Error('Unknown browser');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-01-24 22:12:57 +03:00
|
|
|
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() => {
|
2020-01-29 02:03:10 +03:00
|
|
|
const defaultArgsWithoutUserDataDir = playwright.defaultArgs(defaultBrowserOptions);
|
|
|
|
const defaultArgsWithUserDataDir = playwright.defaultArgs({...defaultBrowserOptions, userDataDir: 'fake-profile'});
|
2020-01-24 22:12:57 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp(Object.assign({}, defaultBrowserOptions, {
|
2020-01-29 02:03:10 +03:00
|
|
|
userDataDir: 'fake-profile',
|
|
|
|
// Filter out any of the args added by the fake profile
|
|
|
|
ignoreDefaultArgs: defaultArgsWithUserDataDir.filter(x => !defaultArgsWithoutUserDataDir.includes(x))
|
2020-01-24 22:12:57 +03:00
|
|
|
}));
|
|
|
|
const spawnargs = browserApp.process().spawnargs;
|
2020-01-29 02:03:10 +03:00
|
|
|
expect(spawnargs.some(x => x.includes('fake-profile'))).toBe(false);
|
2020-01-24 22:12:57 +03:00
|
|
|
await browserApp.close();
|
|
|
|
});
|
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
|
2019-12-03 03:17:53 +03:00
|
|
|
describe('Top-level requires', function() {
|
2019-11-19 05:18:28 +03:00
|
|
|
it('should require top-level Errors', async() => {
|
2020-01-14 04:36:46 +03:00
|
|
|
const Errors = require(path.join(utils.projectRoot(), '/lib/errors.js'));
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(Errors.TimeoutError).toBe(playwright.errors.TimeoutError);
|
|
|
|
});
|
|
|
|
it('should require top-level DeviceDescriptors', async() => {
|
2020-01-14 04:36:46 +03:00
|
|
|
const Devices = require(path.join(utils.projectRoot(), '/lib/deviceDescriptors.js')).DeviceDescriptors;
|
2020-01-28 04:21:39 +03:00
|
|
|
expect(Devices['iPhone 6']).toBeTruthy();
|
2019-11-19 05:18:28 +03:00
|
|
|
expect(Devices['iPhone 6']).toBe(playwright.devices['iPhone 6']);
|
2020-01-28 04:21:39 +03:00
|
|
|
expect(Devices['iPhone 6']).toBe(require(playwrightPath).devices['iPhone 6']);
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
});
|
2020-01-23 04:42:10 +03:00
|
|
|
|
|
|
|
describe('Browser.isConnected', () => {
|
|
|
|
it('should set the browser connected state', async () => {
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect({browserWSEndpoint: browserApp.wsEndpoint()});
|
2020-01-23 04:42:10 +03:00
|
|
|
expect(remote.isConnected()).toBe(true);
|
|
|
|
await remote.disconnect();
|
|
|
|
expect(remote.isConnected()).toBe(false);
|
2020-01-24 01:40:37 +03:00
|
|
|
await browserApp.close();
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
2020-01-23 21:36:13 +03:00
|
|
|
it('should throw when used after isConnected returns false', async({server}) => {
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 21:36:13 +03:00
|
|
|
const page = await remote.defaultContext().newPage();
|
|
|
|
await Promise.all([
|
2020-01-24 01:40:37 +03:00
|
|
|
browserApp.close(),
|
2020-01-23 21:36:13 +03:00
|
|
|
new Promise(f => remote.once('disconnected', f)),
|
|
|
|
]);
|
|
|
|
expect(remote.isConnected()).toBe(false);
|
|
|
|
const error = await page.evaluate('1 + 1').catch(e => e);
|
|
|
|
expect(error.message).toContain('has been closed');
|
|
|
|
});
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Browser.disconnect', function() {
|
|
|
|
it('should reject navigation when browser closes', async({server}) => {
|
|
|
|
server.setRoute('/one-style.css', () => {});
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 04:42:10 +03:00
|
|
|
const page = await remote.defaultContext().newPage();
|
|
|
|
const navigationPromise = page.goto(server.PREFIX + '/one-style.html', {timeout: 60000}).catch(e => e);
|
|
|
|
await server.waitForRequest('/one-style.css');
|
|
|
|
await remote.disconnect();
|
|
|
|
const error = await navigationPromise;
|
|
|
|
expect(error.message).toBe('Navigation failed because browser has disconnected!');
|
2020-01-24 01:40:37 +03:00
|
|
|
await browserApp.close();
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
|
|
|
it('should reject waitForSelector when browser closes', async({server}) => {
|
|
|
|
server.setRoute('/empty.html', () => {});
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 04:42:10 +03:00
|
|
|
const page = await remote.defaultContext().newPage();
|
|
|
|
const watchdog = page.waitForSelector('div', { timeout: 60000 }).catch(e => e);
|
|
|
|
await remote.disconnect();
|
|
|
|
const error = await watchdog;
|
|
|
|
expect(error.message).toContain('Protocol error');
|
2020-01-24 01:40:37 +03:00
|
|
|
await browserApp.close();
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
2020-01-23 21:36:13 +03:00
|
|
|
it('should throw if used after disconnect', async({server}) => {
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 21:36:13 +03:00
|
|
|
const page = await remote.defaultContext().newPage();
|
|
|
|
await remote.disconnect();
|
|
|
|
const error = await page.evaluate('1 + 1').catch(e => e);
|
|
|
|
expect(error.message).toContain('has been closed');
|
2020-01-24 01:40:37 +03:00
|
|
|
await browserApp.close();
|
2020-01-23 21:36:13 +03:00
|
|
|
});
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Browser.close', function() {
|
|
|
|
it('should terminate network waiters', async({context, server}) => {
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 04:42:10 +03:00
|
|
|
const newPage = await remote.defaultContext().newPage();
|
|
|
|
const results = await Promise.all([
|
|
|
|
newPage.waitForRequest(server.EMPTY_PAGE).catch(e => e),
|
|
|
|
newPage.waitForResponse(server.EMPTY_PAGE).catch(e => e),
|
2020-01-24 01:40:37 +03:00
|
|
|
browserApp.close()
|
2020-01-23 04:42:10 +03:00
|
|
|
]);
|
|
|
|
for (let i = 0; i < 2; i++) {
|
|
|
|
const message = results[i].message;
|
|
|
|
expect(message).toContain('Target closed');
|
|
|
|
expect(message).not.toContain('Timeout');
|
|
|
|
}
|
|
|
|
});
|
2020-01-25 02:58:04 +03:00
|
|
|
it('should be able to close remote browser', async({server}) => {
|
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
|
|
|
await Promise.all([
|
|
|
|
new Promise(f => browserApp.once('close', f)),
|
|
|
|
remote.close(),
|
|
|
|
]);
|
|
|
|
});
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
|
|
|
|
2020-01-24 04:45:31 +03:00
|
|
|
describe('Playwright.launch |webSocket| option', function() {
|
|
|
|
it('should not have websocket by default', async() => {
|
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
const browser = await playwright.connect(browserApp.connectOptions());
|
|
|
|
expect((await browser.defaultContext().pages()).length).toBe(1);
|
|
|
|
expect(browserApp.wsEndpoint()).toBe(null);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
|
|
|
await page.close();
|
|
|
|
await browserApp.close();
|
|
|
|
});
|
|
|
|
it('should support the webSocket option', async() => {
|
|
|
|
const options = Object.assign({webSocket: true}, defaultBrowserOptions);
|
|
|
|
const browserApp = await playwright.launchBrowserApp(options);
|
|
|
|
const browser = await playwright.connect(browserApp.connectOptions());
|
|
|
|
expect((await browser.defaultContext().pages()).length).toBe(1);
|
|
|
|
expect(browserApp.wsEndpoint()).not.toBe(null);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
expect(await page.evaluate('11 * 11')).toBe(121);
|
|
|
|
await page.close();
|
|
|
|
await browserApp.close();
|
|
|
|
});
|
|
|
|
it('should fire "disconnected" when closing without webSocket', async() => {
|
|
|
|
const browserApp = await playwright.launchBrowserApp(defaultBrowserOptions);
|
|
|
|
const browser = await playwright.connect(browserApp.connectOptions());
|
|
|
|
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
|
2020-01-25 02:58:04 +03:00
|
|
|
browserApp.kill();
|
2020-01-24 04:45:31 +03:00
|
|
|
await disconnectedEventPromise;
|
|
|
|
});
|
|
|
|
it('should fire "disconnected" when closing with webSocket', async() => {
|
|
|
|
const options = Object.assign({webSocket: true}, defaultBrowserOptions);
|
|
|
|
const browserApp = await playwright.launchBrowserApp(options);
|
|
|
|
const browser = await playwright.connect(browserApp.connectOptions());
|
|
|
|
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
|
2020-01-25 02:58:04 +03:00
|
|
|
browserApp.kill();
|
2020-01-24 04:45:31 +03:00
|
|
|
await disconnectedEventPromise;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-01-23 04:42:10 +03:00
|
|
|
describe('Playwright.connect', function() {
|
|
|
|
it.skip(WEBKIT)('should be able to reconnect to a browser', async({server}) => {
|
2020-01-24 04:45:31 +03:00
|
|
|
const browserApp = await playwright.launchBrowserApp({...defaultBrowserOptions, webSocket: true});
|
2020-01-24 01:40:37 +03:00
|
|
|
const browser = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 04:42:10 +03:00
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
await page.goto(server.PREFIX + '/frames/nested-frames.html');
|
|
|
|
await browser.disconnect();
|
|
|
|
|
2020-01-24 04:45:31 +03:00
|
|
|
const remote = await playwright.connect(browserApp.connectOptions());
|
2020-01-23 04:42:10 +03:00
|
|
|
const pages = await remote.defaultContext().pages();
|
|
|
|
const restoredPage = pages.find(page => page.url() === server.PREFIX + '/frames/nested-frames.html');
|
|
|
|
expect(utils.dumpFrames(restoredPage.mainFrame())).toEqual([
|
|
|
|
'http://localhost:<PORT>/frames/nested-frames.html',
|
|
|
|
' http://localhost:<PORT>/frames/frame.html (aframe)',
|
|
|
|
' http://localhost:<PORT>/frames/two-frames.html (2frames)',
|
|
|
|
' http://localhost:<PORT>/frames/frame.html (dos)',
|
|
|
|
' http://localhost:<PORT>/frames/frame.html (uno)',
|
|
|
|
]);
|
|
|
|
expect(await restoredPage.evaluate(() => 7 * 8)).toBe(56);
|
2020-01-24 01:40:37 +03:00
|
|
|
await browserApp.close();
|
2020-01-23 04:42:10 +03:00
|
|
|
});
|
|
|
|
});
|
2020-01-23 23:18:41 +03:00
|
|
|
|
2020-01-25 04:42:24 +03:00
|
|
|
describe('Playwright.launch({userDataDir})', function() {
|
2020-01-23 23:18:41 +03:00
|
|
|
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);
|
2020-01-24 22:12:57 +03:00
|
|
|
options.args = [...(defaultBrowserOptions.args || [])];
|
|
|
|
if (FFOX)
|
|
|
|
options.args.push('-profile', userDataDir);
|
|
|
|
else
|
|
|
|
options.args.push(`--user-data-dir=${userDataDir}`);
|
2020-01-23 23:18:41 +03:00
|
|
|
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 => {});
|
|
|
|
});
|
2020-01-24 22:12:57 +03:00
|
|
|
it.skip(FFOX)('userDataDir option should restore state', async({server}) => {
|
2020-01-23 23:18:41 +03:00
|
|
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
|
|
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
|
|
|
const browser = await playwright.launch(options);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(() => localStorage.hey = 'hello');
|
|
|
|
await browser.close();
|
|
|
|
|
|
|
|
const browser2 = await playwright.launch(options);
|
|
|
|
const page2 = await browser2.defaultContext().newPage();
|
|
|
|
await page2.goto(server.EMPTY_PAGE);
|
|
|
|
expect(await page2.evaluate(() => localStorage.hey)).toBe('hello');
|
|
|
|
await browser2.close();
|
|
|
|
|
|
|
|
const browser3 = await playwright.launch(defaultBrowserOptions);
|
|
|
|
const page3 = await browser3.defaultContext().newPage();
|
|
|
|
await page3.goto(server.EMPTY_PAGE);
|
|
|
|
expect(await page3.evaluate(() => localStorage.hey)).not.toBe('hello');
|
|
|
|
await browser3.close();
|
|
|
|
|
|
|
|
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
|
|
|
|
await rmAsync(userDataDir).catch(e => {});
|
|
|
|
});
|
2020-01-29 05:04:51 +03:00
|
|
|
// See https://github.com/microsoft/playwright/issues/717
|
|
|
|
it.skip(FFOX || (WIN && CHROMIUM))('userDataDir option should restore cookies', async({server}) => {
|
2020-01-23 23:18:41 +03:00
|
|
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
|
|
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
|
|
|
const browser = await playwright.launch(options);
|
|
|
|
const page = await browser.defaultContext().newPage();
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(() => document.cookie = 'doSomethingOnlyOnce=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
|
|
|
await browser.close();
|
|
|
|
|
|
|
|
const browser2 = await playwright.launch(options);
|
|
|
|
const page2 = await browser2.defaultContext().newPage();
|
|
|
|
await page2.goto(server.EMPTY_PAGE);
|
|
|
|
expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true');
|
|
|
|
await browser2.close();
|
|
|
|
|
|
|
|
const browser3 = await playwright.launch(defaultBrowserOptions);
|
|
|
|
const page3 = await browser3.defaultContext().newPage();
|
|
|
|
await page3.goto(server.EMPTY_PAGE);
|
|
|
|
expect(await page3.evaluate(() => localStorage.hey)).not.toBe('doSomethingOnlyOnce=true');
|
|
|
|
await browser3.close();
|
|
|
|
|
|
|
|
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
|
|
|
|
await rmAsync(userDataDir).catch(e => {});
|
|
|
|
});
|
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
};
|