2020-08-05 01:57:25 +03: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-08-07 00:12:14 +03:00
|
|
|
import path from 'path';
|
2020-09-03 19:43:08 +03:00
|
|
|
import { it, expect, options } from './playwright.fixtures';
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-08-28 14:20:29 +03:00
|
|
|
it('should reject all promises when browser is closed', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browser = await browserType.launch(defaultBrowserOptions);
|
|
|
|
const page = await (await browser.newContext()).newPage();
|
|
|
|
let error = null;
|
|
|
|
const neverResolves = page.evaluate(() => new Promise(r => {})).catch(e => error = e);
|
|
|
|
await page.evaluate(() => new Promise(f => setTimeout(f, 0)));
|
|
|
|
await browser.close();
|
|
|
|
await neverResolves;
|
|
|
|
expect(error.message).toContain('Protocol error');
|
|
|
|
});
|
|
|
|
|
2020-08-28 14:20:29 +03:00
|
|
|
it('should throw if userDataDir option is passed', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
let waitError = null;
|
|
|
|
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
|
|
|
|
await browserType.launch(options).catch(e => waitError = e);
|
|
|
|
expect(waitError.message).toContain('launchPersistentContext');
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should throw if page argument is passed', test => {
|
|
|
|
test.skip(options.FIREFOX);
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should reject if launched browser fails immediately', test => {
|
|
|
|
test.fixme(`I'm getting ENCONRESET on this one.`);
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const options = Object.assign({}, defaultBrowserOptions, {executablePath: path.join(__dirname, 'assets', 'dummy_bad_browser_executable.js')});
|
|
|
|
let waitError = null;
|
|
|
|
await browserType.launch(options).catch(e => waitError = e);
|
|
|
|
expect(waitError.message).toContain('== logs ==');
|
|
|
|
});
|
|
|
|
|
2020-08-28 14:20:29 +03:00
|
|
|
it('should reject if executable path is invalid', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
let waitError = null;
|
|
|
|
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
|
|
|
|
await browserType.launch(options).catch(e => waitError = e);
|
|
|
|
expect(waitError.message).toContain('Failed to launch');
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should handle timeout', test => {
|
|
|
|
test.skip(options.WIRE);
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };
|
|
|
|
const error = await browserType.launch(options).catch(e => e);
|
|
|
|
expect(error.message).toContain(`browserType.launch: Timeout 5000ms exceeded.`);
|
2020-08-18 00:12:31 +03:00
|
|
|
expect(error.message).toContain(`<launching>`);
|
|
|
|
expect(error.message).toContain(`<launched> pid=`);
|
2020-08-05 01:57:25 +03:00
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should handle exception', test => {
|
|
|
|
test.skip(options.WIRE);
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const e = new Error('Dummy');
|
|
|
|
const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 };
|
|
|
|
const error = await browserType.launch(options).catch(e => e);
|
|
|
|
expect(error.message).toContain('Dummy');
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should report launch log', test => {
|
|
|
|
test.skip(options.WIRE);
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const e = new Error('Dummy');
|
|
|
|
const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 };
|
|
|
|
const error = await browserType.launch(options).catch(e => e);
|
|
|
|
expect(error.message).toContain('<launching>');
|
|
|
|
});
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
it('should accept objects as options', test => {
|
|
|
|
test.slow();
|
|
|
|
}, async ({browserType, defaultBrowserOptions}) => {
|
2020-08-07 00:12:14 +03:00
|
|
|
const browser = await browserType.launch({ ...defaultBrowserOptions, process } as any);
|
2020-08-05 01:57:25 +03:00
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
|
2020-08-28 14:20:29 +03:00
|
|
|
it('should fire close event for all contexts', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browser = await browserType.launch(defaultBrowserOptions);
|
|
|
|
const context = await browser.newContext();
|
|
|
|
let closed = false;
|
|
|
|
context.on('close', () => closed = true);
|
|
|
|
await browser.close();
|
|
|
|
expect(closed).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-08-28 14:20:29 +03:00
|
|
|
it('should be callable twice', async ({browserType, defaultBrowserOptions}) => {
|
2020-08-05 01:57:25 +03:00
|
|
|
const browser = await browserType.launch(defaultBrowserOptions);
|
|
|
|
await Promise.all([
|
|
|
|
browser.close(),
|
|
|
|
browser.close(),
|
|
|
|
]);
|
|
|
|
await browser.close();
|
|
|
|
});
|