2018-03-16 22:33:31 +00:00
|
|
|
/**
|
2019-01-24 06:04:42 +00:00
|
|
|
* Copyright 2019 Google Inc. All rights reserved.
|
2018-03-16 22:33:31 +00: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');
|
|
|
|
const path = require('path');
|
2019-01-24 06:04:42 +00:00
|
|
|
const rm = require('rimraf').sync;
|
|
|
|
const GoldenUtils = require('./golden-utils');
|
|
|
|
const {Matchers} = require('../utils/testrunner/');
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
const YELLOW_COLOR = '\x1b[33m';
|
|
|
|
const RESET_COLOR = '\x1b[0m';
|
|
|
|
|
2019-02-25 20:40:17 +00:00
|
|
|
module.exports.addTests = ({testRunner, product, puppeteerPath}) => {
|
2019-02-14 03:47:14 +00:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
|
|
|
const {it, fit, xit} = testRunner;
|
2018-03-20 03:00:12 +00:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2019-02-02 01:04:19 +00:00
|
|
|
const CHROME = product === 'Chromium';
|
2019-02-02 01:55:12 +00:00
|
|
|
const FFOX = product === 'Firefox';
|
2019-02-02 01:04:19 +00:00
|
|
|
|
2019-02-25 20:40:17 +00:00
|
|
|
const puppeteer = require(puppeteerPath);
|
|
|
|
|
2019-02-05 21:38:56 +00:00
|
|
|
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
|
|
|
const slowMo = parseInt((process.env.SLOW_MO || '0').trim(), 10);
|
|
|
|
|
2019-02-05 21:17:02 +00:00
|
|
|
const defaultBrowserOptions = {
|
|
|
|
handleSIGINT: false,
|
|
|
|
executablePath: CHROME ? process.env.CHROME : process.env.FFOX,
|
|
|
|
slowMo,
|
|
|
|
headless,
|
2019-02-13 01:38:48 +00:00
|
|
|
dumpio: !!process.env.DUMPIO,
|
2019-02-05 21:17:02 +00:00
|
|
|
};
|
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
if (defaultBrowserOptions.executablePath) {
|
|
|
|
console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}${RESET_COLOR}`);
|
|
|
|
} else {
|
|
|
|
// Make sure the `npm install` was run after the chromium roll.
|
|
|
|
if (!fs.existsSync(puppeteer.executablePath()))
|
|
|
|
throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GOLDEN_DIR = path.join(__dirname, 'golden-' + product.toLowerCase());
|
|
|
|
const OUTPUT_DIR = path.join(__dirname, 'output-' + product.toLowerCase());
|
|
|
|
if (fs.existsSync(OUTPUT_DIR))
|
|
|
|
rm(OUTPUT_DIR);
|
|
|
|
const {expect} = new Matchers({
|
|
|
|
toBeGolden: GoldenUtils.compare.bind(null, GOLDEN_DIR, OUTPUT_DIR)
|
|
|
|
});
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
const testOptions = {
|
|
|
|
testRunner,
|
|
|
|
product,
|
2019-02-02 01:55:12 +00:00
|
|
|
FFOX,
|
|
|
|
CHROME,
|
2019-01-24 06:04:42 +00:00
|
|
|
puppeteer,
|
|
|
|
expect,
|
|
|
|
defaultBrowserOptions,
|
2019-02-25 20:40:17 +00:00
|
|
|
puppeteerPath,
|
2019-01-24 06:04:42 +00:00
|
|
|
headless: !!defaultBrowserOptions.headless,
|
|
|
|
};
|
|
|
|
|
2019-02-05 21:17:02 +00:00
|
|
|
beforeAll(async() => {
|
|
|
|
if (FFOX && defaultBrowserOptions.executablePath)
|
|
|
|
await require('../experimental/puppeteer-firefox/misc/install-preferences')(defaultBrowserOptions.executablePath);
|
|
|
|
});
|
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
describe('Browser', function() {
|
|
|
|
beforeAll(async state => {
|
|
|
|
state.browser = await puppeteer.launch(defaultBrowserOptions);
|
2018-09-14 18:44:54 +00:00
|
|
|
});
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
afterAll(async state => {
|
|
|
|
await state.browser.close();
|
|
|
|
state.browser = null;
|
2018-03-16 22:33:31 +00:00
|
|
|
});
|
2019-01-14 21:23:34 +00:00
|
|
|
|
2019-01-24 06:04:42 +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-03-16 22:33:31 +00:00
|
|
|
});
|
2018-04-09 23:38:00 +00:00
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
afterEach(async state => {
|
|
|
|
state.tearDown();
|
2018-08-01 22:49:41 +00:00
|
|
|
});
|
|
|
|
|
2019-01-24 06:04:42 +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.
|
2019-02-26 05:57:33 +00:00
|
|
|
require('./accessibility.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./browser.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./click.spec.js').addTests(testOptions);
|
2019-02-06 06:32:41 +00:00
|
|
|
require('./cookies.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./dialog.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./elementhandle.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./emulation.spec.js').addTests(testOptions);
|
|
|
|
require('./evaluation.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./frame.spec.js').addTests(testOptions);
|
|
|
|
require('./input.spec.js').addTests(testOptions);
|
|
|
|
require('./jshandle.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./keyboard.spec.js').addTests(testOptions);
|
|
|
|
require('./mouse.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./navigation.spec.js').addTests(testOptions);
|
2019-02-06 06:32:41 +00:00
|
|
|
require('./network.spec.js').addTests(testOptions);
|
2019-04-12 01:33:01 +00:00
|
|
|
require('./requestinterception.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./page.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./screenshot.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./queryselector.spec.js').addTests(testOptions);
|
2019-01-24 06:04:42 +00:00
|
|
|
require('./target.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./touchscreen.spec.js').addTests(testOptions);
|
|
|
|
require('./waittask.spec.js').addTests(testOptions);
|
2019-02-06 06:32:41 +00:00
|
|
|
require('./worker.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
if (CHROME) {
|
|
|
|
require('./CDPSession.spec.js').addTests(testOptions);
|
|
|
|
require('./coverage.spec.js').addTests(testOptions);
|
2019-02-25 20:51:06 +00:00
|
|
|
// Add page-level Chromium-specific tests.
|
|
|
|
require('./chromiumonly.spec.js').addPageTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
}
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
2019-01-24 06:04:42 +00:00
|
|
|
|
|
|
|
// Browser-level tests that are given a browser.
|
|
|
|
require('./browsercontext.spec.js').addTests(testOptions);
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
|
|
|
|
2019-01-24 06:04:42 +00:00
|
|
|
// Top-level tests that launch Browser themselves.
|
|
|
|
require('./ignorehttpserrors.spec.js').addTests(testOptions);
|
|
|
|
require('./launcher.spec.js').addTests(testOptions);
|
2019-02-25 20:40:17 +00:00
|
|
|
require('./fixtures.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
if (CHROME) {
|
2019-05-29 23:49:44 +00:00
|
|
|
require('./oopif.spec.js').addTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
require('./headful.spec.js').addTests(testOptions);
|
|
|
|
require('./tracing.spec.js').addTests(testOptions);
|
2019-02-25 20:51:06 +00:00
|
|
|
// Add top-level Chromium-specific tests.
|
|
|
|
require('./chromiumonly.spec.js').addLauncherTests(testOptions);
|
2019-02-02 01:04:19 +00:00
|
|
|
}
|
2018-03-16 22:33:31 +00:00
|
|
|
};
|