test: split out headful tests into headful.spec.js (#2657)
This commit is contained in:
parent
e03802688d
commit
07b91f61a9
79
test/headful.spec.js
Normal file
79
test/headful.spec.js
Normal file
@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright 2018 Google Inc. All rights reserved.
|
||||
*
|
||||
* 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 os = require('os');
|
||||
|
||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
|
||||
module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions}) {
|
||||
const {describe, xdescribe, fdescribe} = testRunner;
|
||||
const {it, fit, xit} = testRunner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||
const puppeteer = require(PROJECT_ROOT);
|
||||
|
||||
const headfulOptions = Object.assign({}, defaultBrowserOptions, {
|
||||
headless: false
|
||||
});
|
||||
const headlessOptions = Object.assign({}, defaultBrowserOptions, {
|
||||
headless: true
|
||||
});
|
||||
const extensionPath = path.join(__dirname, 'assets', 'simple-extension');
|
||||
const extensionOptions = Object.assign({}, defaultBrowserOptions, {
|
||||
headless: false,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
`--disable-extensions-except=${extensionPath}`,
|
||||
`--load-extension=${extensionPath}`,
|
||||
],
|
||||
});
|
||||
|
||||
describe('HEADFUL', function() {
|
||||
it('background_page target type should be available', async({browser}) => {
|
||||
const browserWithExtension = await puppeteer.launch(extensionOptions);
|
||||
const page = await browserWithExtension.newPage();
|
||||
const targets = await browserWithExtension.targets();
|
||||
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
|
||||
await page.close();
|
||||
await browserWithExtension.close();
|
||||
expect(backgroundPageTarget).toBeTruthy();
|
||||
});
|
||||
it('should have default url when launching browser', async function() {
|
||||
const browser = await puppeteer.launch(extensionOptions);
|
||||
const pages = (await browser.pages()).map(page => page.url());
|
||||
expect(pages).toEqual(['about:blank']);
|
||||
await browser.close();
|
||||
});
|
||||
xit('headless should be able to read cookies written by headful', async({server}) => {
|
||||
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||
// Write a cookie in headful chrome
|
||||
const headfulBrowser = await puppeteer.launch(Object.assign({userDataDir}, headfulOptions));
|
||||
const headfulPage = await headfulBrowser.newPage();
|
||||
await headfulPage.goto(server.EMPTY_PAGE);
|
||||
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
||||
await headfulBrowser.close();
|
||||
// Read the cookie from headless chrome
|
||||
const headlessBrowser = await puppeteer.launch(Object.assign({userDataDir}, headlessOptions));
|
||||
const headlessPage = await headlessBrowser.newPage();
|
||||
await headlessPage.goto(server.EMPTY_PAGE);
|
||||
const cookie = await headlessPage.evaluate(() => document.cookie);
|
||||
await headlessBrowser.close();
|
||||
rm(userDataDir);
|
||||
expect(cookie).toBe('foo=true');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -178,26 +178,6 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
|
||||
await browser2.close();
|
||||
rm(userDataDir);
|
||||
});
|
||||
xit('headless should be able to read cookies written by headful', async({server}) => {
|
||||
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
||||
// Write a cookie in headful chrome
|
||||
options.headless = false;
|
||||
const headfulBrowser = await puppeteer.launch(options);
|
||||
const headfulPage = await headfulBrowser.newPage();
|
||||
await headfulPage.goto(server.EMPTY_PAGE);
|
||||
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
||||
await headfulBrowser.close();
|
||||
// Read the cookie from headless chrome
|
||||
options.headless = true;
|
||||
const headlessBrowser = await puppeteer.launch(options);
|
||||
const headlessPage = await headlessBrowser.newPage();
|
||||
await headlessPage.goto(server.EMPTY_PAGE);
|
||||
const cookie = await headlessPage.evaluate(() => document.cookie);
|
||||
await headlessBrowser.close();
|
||||
rm(userDataDir);
|
||||
expect(cookie).toBe('foo=true');
|
||||
});
|
||||
it('should return the default chrome arguments', async() => {
|
||||
const args = puppeteer.defaultArgs();
|
||||
expect(args).toContain('--no-first-run');
|
||||
@ -270,13 +250,6 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
|
||||
expect(pages).toEqual(['about:blank']);
|
||||
await browser.close();
|
||||
});
|
||||
it('should have default url when launching browser with headless:false', async function() {
|
||||
const options = Object.assign({}, defaultBrowserOptions, {headless: false});
|
||||
const browser = await puppeteer.launch(options);
|
||||
const pages = (await browser.pages()).map(page => page.url());
|
||||
expect(pages).toEqual(['about:blank']);
|
||||
await browser.close();
|
||||
});
|
||||
it('should have custom url when launching browser', async function({server}) {
|
||||
const customUrl = server.PREFIX + '/empty.html';
|
||||
const options = Object.assign({}, defaultBrowserOptions);
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
const {waitEvent} = require('./utils');
|
||||
|
||||
module.exports.addTests = function({testRunner, expect, puppeteer, browserWithExtensionOptions}) {
|
||||
module.exports.addTests = function({testRunner, expect, puppeteer}) {
|
||||
const {describe, xdescribe, fdescribe} = testRunner;
|
||||
const {it, fit, xit} = testRunner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||
@ -36,15 +36,6 @@ module.exports.addTests = function({testRunner, expect, puppeteer, browserWithEx
|
||||
expect(allPages).toContain(page);
|
||||
expect(allPages[0]).not.toBe(allPages[1]);
|
||||
});
|
||||
it('should allow background_page target type to pass through', async({browser}) => {
|
||||
const browserWithExtension = await puppeteer.launch(browserWithExtensionOptions);
|
||||
const page = await browserWithExtension.newPage();
|
||||
const targets = await browserWithExtension.targets();
|
||||
const backgroundPageTarget = targets.find(target => target.type() === 'background_page');
|
||||
await page.close();
|
||||
await browserWithExtension.close();
|
||||
expect(backgroundPageTarget).toBeTruthy();
|
||||
});
|
||||
it('should contain browser target', async({browser}) => {
|
||||
const targets = browser.targets();
|
||||
const browserTarget = targets.find(target => target.type() === 'browser');
|
||||
|
13
test/test.js
13
test/test.js
@ -35,7 +35,6 @@ const RESET_COLOR = '\x1b[0m';
|
||||
|
||||
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
||||
const executablePath = process.env.CHROME;
|
||||
const extensionPath = path.resolve(__dirname, '../test/assets/simple-extension');
|
||||
|
||||
if (executablePath)
|
||||
console.warn(`${YELLOW_COLOR}WARN: running tests with ${executablePath}${RESET_COLOR}`);
|
||||
@ -50,15 +49,6 @@ const defaultBrowserOptions = {
|
||||
dumpio: (process.env.DUMPIO || 'false').trim().toLowerCase() === 'true',
|
||||
args: ['--no-sandbox']
|
||||
};
|
||||
const browserWithExtensionOptions = {
|
||||
headless: false,
|
||||
executablePath,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
`--disable-extensions-except=${extensionPath}`,
|
||||
`--load-extension=${extensionPath}`,
|
||||
],
|
||||
};
|
||||
|
||||
let parallel = 1;
|
||||
if (process.env.PPTR_PARALLEL_TESTS)
|
||||
@ -153,12 +143,13 @@ describe('Page', function() {
|
||||
require('./jshandle.spec.js').addTests({testRunner, expect});
|
||||
require('./network.spec.js').addTests({testRunner, expect});
|
||||
require('./page.spec.js').addTests({testRunner, expect, puppeteer, DeviceDescriptors, headless});
|
||||
require('./target.spec.js').addTests({testRunner, expect, puppeteer, browserWithExtensionOptions});
|
||||
require('./target.spec.js').addTests({testRunner, expect, puppeteer});
|
||||
require('./tracing.spec.js').addTests({testRunner, expect});
|
||||
});
|
||||
|
||||
// Top-level tests that launch Browser themselves.
|
||||
require('./puppeteer.spec.js').addTests({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions});
|
||||
require('./headful.spec.js').addTests({testRunner, expect, PROJECT_ROOT, defaultBrowserOptions});
|
||||
|
||||
if (process.env.COVERAGE) {
|
||||
describe('COVERAGE', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user