2017-06-15 15:15:25 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 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.
|
|
|
|
*/
|
2017-08-02 19:06:47 +00:00
|
|
|
const fs = require('fs');
|
2018-04-11 01:05:10 +00:00
|
|
|
const rm = require('rimraf').sync;
|
2017-08-02 19:06:47 +00:00
|
|
|
const path = require('path');
|
2018-09-24 19:46:39 +00:00
|
|
|
const {TestServer} = require('../utils/testserver/');
|
2018-03-16 22:33:31 +00:00
|
|
|
const GoldenUtils = require('./golden-utils');
|
|
|
|
const GOLDEN_DIR = path.join(__dirname, 'golden');
|
|
|
|
const OUTPUT_DIR = path.join(__dirname, 'output');
|
|
|
|
const {TestRunner, Reporter, Matchers} = require('../utils/testrunner/');
|
2018-08-09 23:51:12 +00:00
|
|
|
const utils = require('./utils');
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2018-07-30 23:41:39 +00:00
|
|
|
const {helper, assert} = require('../lib/helper');
|
2017-07-27 23:16:37 +00:00
|
|
|
if (process.env.COVERAGE)
|
|
|
|
helper.recordPublicAPICoverage();
|
2017-12-08 23:14:28 +00:00
|
|
|
|
2018-08-09 23:51:12 +00:00
|
|
|
const puppeteer = utils.requireRoot('index');
|
2017-08-02 19:06:47 +00:00
|
|
|
|
2017-08-04 04:38:55 +00:00
|
|
|
const YELLOW_COLOR = '\x1b[33m';
|
|
|
|
const RESET_COLOR = '\x1b[0m';
|
|
|
|
|
2017-07-20 02:35:09 +00:00
|
|
|
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
2017-08-04 04:38:55 +00:00
|
|
|
const executablePath = process.env.CHROME;
|
2017-12-08 23:14:28 +00:00
|
|
|
|
2017-08-04 04:38:55 +00:00
|
|
|
if (executablePath)
|
|
|
|
console.warn(`${YELLOW_COLOR}WARN: running tests with ${executablePath}${RESET_COLOR}`);
|
2017-12-08 23:14:28 +00:00
|
|
|
// Make sure the `npm install` was run after the chromium roll.
|
2018-05-31 23:53:51 +00:00
|
|
|
assert(fs.existsSync(puppeteer.executablePath()), `Chromium is not Downloaded. Run 'npm install' and try to re-run tests`);
|
2017-08-04 04:38:55 +00:00
|
|
|
|
2018-03-16 22:33:31 +00:00
|
|
|
const slowMo = parseInt((process.env.SLOW_MO || '0').trim(), 10);
|
2017-08-04 04:38:55 +00:00
|
|
|
const defaultBrowserOptions = {
|
2018-07-31 01:07:01 +00:00
|
|
|
handleSIGINT: false,
|
2017-08-04 04:38:55 +00:00
|
|
|
executablePath,
|
|
|
|
slowMo,
|
|
|
|
headless,
|
2018-05-29 22:45:03 +00:00
|
|
|
dumpio: (process.env.DUMPIO || 'false').trim().toLowerCase() === 'true',
|
2017-08-04 04:38:55 +00:00
|
|
|
};
|
2017-08-01 01:47:56 +00:00
|
|
|
|
2017-12-12 21:34:21 +00:00
|
|
|
let parallel = 1;
|
|
|
|
if (process.env.PPTR_PARALLEL_TESTS)
|
|
|
|
parallel = parseInt(process.env.PPTR_PARALLEL_TESTS.trim(), 10);
|
|
|
|
const parallelArgIndex = process.argv.indexOf('-j');
|
|
|
|
if (parallelArgIndex !== -1)
|
|
|
|
parallel = parseInt(process.argv[parallelArgIndex + 1], 10);
|
2018-01-04 20:08:35 +00:00
|
|
|
require('events').defaultMaxListeners *= parallel;
|
2017-12-08 00:37:22 +00:00
|
|
|
|
2018-03-16 22:33:31 +00:00
|
|
|
const timeout = slowMo ? 0 : 10 * 1000;
|
2018-04-09 23:38:00 +00:00
|
|
|
const testRunner = new TestRunner({timeout, parallel});
|
2017-12-08 00:37:22 +00:00
|
|
|
const {expect} = new Matchers({
|
|
|
|
toBeGolden: GoldenUtils.compare.bind(null, GOLDEN_DIR, OUTPUT_DIR)
|
2017-11-20 23:59:07 +00:00
|
|
|
});
|
2018-04-09 23:38:00 +00:00
|
|
|
const {describe, it, xit, beforeAll, afterAll, beforeEach, afterEach} = testRunner;
|
2017-11-20 23:59:07 +00:00
|
|
|
|
2017-12-12 21:34:21 +00:00
|
|
|
if (fs.existsSync(OUTPUT_DIR))
|
|
|
|
rm(OUTPUT_DIR);
|
|
|
|
|
2018-03-16 22:33:31 +00:00
|
|
|
console.log('Testing on Node', process.version);
|
|
|
|
|
2018-05-16 21:36:34 +00:00
|
|
|
beforeAll(async state => {
|
2017-08-01 22:17:57 +00:00
|
|
|
const assetsPath = path.join(__dirname, 'assets');
|
2018-02-05 22:59:07 +00:00
|
|
|
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
|
|
|
|
2017-12-12 21:34:21 +00:00
|
|
|
const port = 8907 + state.parallelIndex * 2;
|
2018-09-24 19:46:39 +00:00
|
|
|
state.server = await TestServer.create(assetsPath, port);
|
2018-02-05 22:59:07 +00:00
|
|
|
state.server.enableHTTPCache(cachedPath);
|
2018-09-04 19:39:59 +00:00
|
|
|
state.server.PORT = port;
|
2017-12-12 21:34:21 +00:00
|
|
|
state.server.PREFIX = `http://localhost:${port}`;
|
|
|
|
state.server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`;
|
|
|
|
state.server.EMPTY_PAGE = `http://localhost:${port}/empty.html`;
|
|
|
|
|
|
|
|
const httpsPort = port + 1;
|
2018-09-24 19:46:39 +00:00
|
|
|
state.httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort);
|
2018-02-05 22:59:07 +00:00
|
|
|
state.httpsServer.enableHTTPCache(cachedPath);
|
2018-09-04 19:39:59 +00:00
|
|
|
state.httpsServer.PORT = httpsPort;
|
2017-12-12 21:34:21 +00:00
|
|
|
state.httpsServer.PREFIX = `https://localhost:${httpsPort}`;
|
|
|
|
state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`;
|
|
|
|
state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`;
|
|
|
|
});
|
2017-08-01 22:17:57 +00:00
|
|
|
|
2018-03-20 03:00:12 +00:00
|
|
|
afterAll(async({server, httpsServer}) => {
|
2017-08-01 22:17:57 +00:00
|
|
|
await Promise.all([
|
|
|
|
server.stop(),
|
|
|
|
httpsServer.stop(),
|
|
|
|
]);
|
2017-12-12 21:34:21 +00:00
|
|
|
});
|
2017-08-01 22:17:57 +00:00
|
|
|
|
2018-04-09 23:38:00 +00:00
|
|
|
beforeEach(async({server, httpsServer}) => {
|
|
|
|
server.reset();
|
|
|
|
httpsServer.reset();
|
|
|
|
});
|
|
|
|
|
2018-08-01 22:49:41 +00:00
|
|
|
describe('Browser', function() {
|
2018-04-09 23:38:00 +00:00
|
|
|
beforeAll(async state => {
|
|
|
|
state.browser = await puppeteer.launch(defaultBrowserOptions);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async state => {
|
|
|
|
await state.browser.close();
|
|
|
|
state.browser = null;
|
|
|
|
});
|
|
|
|
|
2018-05-29 22:45:03 +00:00
|
|
|
beforeEach(async(state, test) => {
|
|
|
|
const rl = require('readline').createInterface({input: state.browser.process().stderr});
|
|
|
|
test.output = '';
|
|
|
|
rl.on('line', onLine);
|
|
|
|
state.tearDown = () => {
|
|
|
|
rl.removeListener('line', onLine);
|
|
|
|
rl.close();
|
|
|
|
};
|
|
|
|
function onLine(line) {
|
|
|
|
test.output += line + '\n';
|
|
|
|
}
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async state => {
|
2018-05-29 22:45:03 +00:00
|
|
|
state.tearDown();
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
|
|
|
|
2018-08-01 22:49:41 +00:00
|
|
|
describe('Page', function() {
|
|
|
|
beforeEach(async state => {
|
|
|
|
state.context = await state.browser.createIncognitoBrowserContext();
|
|
|
|
state.page = await state.context.newPage();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async state => {
|
|
|
|
// This closes all pages.
|
|
|
|
await state.context.close();
|
|
|
|
state.context = null;
|
|
|
|
state.page = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Page-level tests that are given a browser, a context and a page.
|
|
|
|
// Each test is launched in a new browser context.
|
|
|
|
require('./CDPSession.spec.js').addTests({testRunner, expect});
|
2018-11-02 01:54:51 +00:00
|
|
|
require('./accessibility.spec.js').addTests({testRunner, expect});
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./browser.spec.js').addTests({testRunner, expect, headless});
|
2018-08-01 22:49:41 +00:00
|
|
|
require('./cookies.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./coverage.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./elementhandle.spec.js').addTests({testRunner, expect});
|
2018-11-21 02:45:37 +00:00
|
|
|
require('./queryselector.spec.js').addTests({testRunner, expect});
|
2018-11-21 02:57:28 +00:00
|
|
|
require('./waittask.spec.js').addTests({testRunner, expect});
|
2018-08-01 22:49:41 +00:00
|
|
|
require('./frame.spec.js').addTests({testRunner, expect});
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./input.spec.js').addTests({testRunner, expect});
|
2018-11-21 03:43:07 +00:00
|
|
|
require('./mouse.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./keyboard.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./touchscreen.spec.js').addTests({testRunner, expect});
|
2018-11-21 03:34:57 +00:00
|
|
|
require('./click.spec.js').addTests({testRunner, expect});
|
2018-08-01 22:49:41 +00:00
|
|
|
require('./jshandle.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./network.spec.js').addTests({testRunner, expect});
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./page.spec.js').addTests({testRunner, expect, headless});
|
2018-11-21 04:18:57 +00:00
|
|
|
require('./dialog.spec.js').addTests({testRunner, expect, headless});
|
2018-11-21 04:09:25 +00:00
|
|
|
require('./navigation.spec.js').addTests({testRunner, expect, headless});
|
2018-11-21 03:59:59 +00:00
|
|
|
require('./evaluation.spec.js').addTests({testRunner, expect, headless});
|
2018-11-21 03:17:56 +00:00
|
|
|
require('./emulation.spec.js').addTests({testRunner, expect, headless});
|
2018-11-21 02:32:42 +00:00
|
|
|
require('./screenshot.spec.js').addTests({testRunner, expect});
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./target.spec.js').addTests({testRunner, expect});
|
2018-08-01 22:49:41 +00:00
|
|
|
require('./tracing.spec.js').addTests({testRunner, expect});
|
|
|
|
require('./worker.spec.js').addTests({testRunner, expect});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Browser-level tests that are given a browser.
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./browsercontext.spec.js').addTests({testRunner, expect});
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
2017-12-08 00:37:22 +00:00
|
|
|
|
2018-04-10 06:38:20 +00:00
|
|
|
// Top-level tests that launch Browser themselves.
|
2018-08-09 23:51:12 +00:00
|
|
|
require('./ignorehttpserrors.spec.js').addTests({testRunner, expect, defaultBrowserOptions});
|
|
|
|
require('./puppeteer.spec.js').addTests({testRunner, expect, defaultBrowserOptions});
|
|
|
|
require('./headful.spec.js').addTests({testRunner, expect, defaultBrowserOptions});
|
2018-04-10 06:38:20 +00:00
|
|
|
|
2018-03-20 03:00:12 +00:00
|
|
|
if (process.env.COVERAGE) {
|
2018-05-16 21:36:34 +00:00
|
|
|
describe('COVERAGE', function() {
|
2018-03-20 03:00:12 +00:00
|
|
|
const coverage = helper.publicAPICoverage();
|
|
|
|
const disabled = new Set(['page.bringToFront']);
|
2018-04-09 23:38:00 +00:00
|
|
|
if (!headless)
|
2018-03-20 03:00:12 +00:00
|
|
|
disabled.add('page.pdf');
|
|
|
|
|
|
|
|
for (const method of coverage.keys()) {
|
|
|
|
(disabled.has(method) ? xit : it)(`public api '${method}' should be called`, async({page, server}) => {
|
|
|
|
expect(coverage.get(method)).toBe(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-09 23:38:00 +00:00
|
|
|
if (process.env.CI && testRunner.hasFocusedTestsOrSuites()) {
|
2017-12-28 23:41:57 +00:00
|
|
|
console.error('ERROR: "focused" tests/suites are prohibitted on bots. Remove any "fit"/"fdescribe" declarations.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-04-09 23:38:00 +00:00
|
|
|
|
2018-09-17 22:22:53 +00:00
|
|
|
new Reporter(testRunner, utils.projectRoot());
|
2018-04-09 23:38:00 +00:00
|
|
|
testRunner.run();
|