test: remove module.export.describe wrapper (#1716)

This commit is contained in:
Dmitry Gozman 2020-04-08 15:19:09 -07:00 committed by GitHub
parent 2ef8e26602
commit ade9d23c28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 10728 additions and 10940 deletions

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
describe('Accessibility', function() { describe('Accessibility', function() {
it('should work', async function({page}) { it('should work', async function({page}) {
@ -351,4 +348,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
}); });
}); });
}); });
};

View file

@ -48,8 +48,7 @@ function traceAPICoverage(apiCoverage, events, className, classType) {
} }
} }
module.exports.describe = function({browserType}) { describe.skip(!process.env.COVERAGE)('**API COVERAGE**', () => {
describe('**API COVERAGE**', () => {
const BROWSER_CONFIGS = [ const BROWSER_CONFIGS = [
{ {
name: 'Firefox', name: 'Firefox',
@ -100,4 +99,3 @@ module.exports.describe = function({browserType}) {
throw new Error('Certain API Methods are not called: ' + missingMethods.join(', ')); throw new Error('Certain API Methods are not called: ' + missingMethods.join(', '));
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
describe('Auto waiting', () => { describe('Auto waiting', () => {
it('should await navigation when clicking anchor', async({page, server}) => { it('should await navigation when clicking anchor', async({page, server}) => {
@ -226,5 +223,4 @@ module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT
}); });
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {BrowserTestSuite}
*/
module.exports.describe = function({playwright, CHROMIUM, WEBKIT}) {
describe('Browser.newPage', function() { describe('Browser.newPage', function() {
it('should create new page', async function({browser}) { it('should create new page', async function({browser}) {
@ -41,4 +38,3 @@ module.exports.describe = function({playwright, CHROMIUM, WEBKIT}) {
expect(error.message).toContain('Please use browser.newContext()'); expect(error.message).toContain('Please use browser.newContext()');
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
/**
* @type {BrowserTestSuite}
*/
module.exports.describe = function({playwright, CHROMIUM, FFOX, WEBKIT, LINUX}) {
describe('BrowserContext', function() { describe('BrowserContext', function() {
it('should create new context', async function({browser}) { it('should create new context', async function({browser}) {
@ -620,4 +616,3 @@ module.exports.describe = function({playwright, CHROMIUM, FFOX, WEBKIT, LINUX})
await context.close(); await context.close();
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT, WIN} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({WIN, WEBKIT}) {
describe('Capabilities', function() { describe('Capabilities', function() {
it.fail(WEBKIT && WIN)('Web Assembly should work', async function({page, server}) { it.fail(WEBKIT && WIN)('Web Assembly should work', async function({page, server}) {
@ -25,4 +22,3 @@ module.exports.describe = function({WIN, WEBKIT}) {
expect(await page.evaluate(() => loadTable())).toBe('42, 83'); expect(await page.evaluate(() => loadTable())).toBe('42, 83');
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('../utils').testOptions(browserType);
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('ChromiumBrowserContext', function() { describe('ChromiumBrowserContext', function() {
it('should create a worker from a service worker', async({browser, page, server, context}) => { it('should create a worker from a service worker', async({browser, page, server, context}) => {
@ -76,5 +73,3 @@ module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
expect(serverRequest.headers.intervention).toContain('feature/5718547946799104'); expect(serverRequest.headers.intervention).toContain('feature/5718547946799104');
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('../utils').testOptions(browserType);
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
describe('JSCoverage', function() { describe('JSCoverage', function() {
it('should work', async function({page, server}) { it('should work', async function({page, server}) {
@ -185,4 +182,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
expect(coverage.length).toBe(1); expect(coverage.length).toBe(1);
}); });
}); });
};

View file

@ -14,16 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
const util = require('util');
const fs = require('fs');
const path = require('path'); const path = require('path');
const os = require('os'); const utils = require('../utils');
const { makeUserDataDir, removeUserDataDir } = require('../utils'); const {makeUserDataDir, removeUserDataDir} = utils;
const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions} = utils.testOptions(browserType);
/**
* @type {TestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false
@ -38,19 +32,19 @@ module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
}); });
describe('launcher', function() { describe('launcher', function() {
it('should throw with remote-debugging-pipe argument', async() => { it('should throw with remote-debugging-pipe argument', async({browserType}) => {
const options = Object.assign({}, defaultBrowserOptions); const options = Object.assign({}, defaultBrowserOptions);
options.args = ['--remote-debugging-pipe'].concat(options.args || []); options.args = ['--remote-debugging-pipe'].concat(options.args || []);
const error = await browserType.launchServer(options).catch(e => e); const error = await browserType.launchServer(options).catch(e => e);
expect(error.message).toContain('Playwright manages remote debugging connection itself'); expect(error.message).toContain('Playwright manages remote debugging connection itself');
}); });
it('should throw with remote-debugging-port argument', async() => { it('should throw with remote-debugging-port argument', async({browserType}) => {
const options = Object.assign({}, defaultBrowserOptions); const options = Object.assign({}, defaultBrowserOptions);
options.args = ['--remote-debugging-port=9222'].concat(options.args || []); options.args = ['--remote-debugging-port=9222'].concat(options.args || []);
const error = await browserType.launchServer(options).catch(e => e); const error = await browserType.launchServer(options).catch(e => e);
expect(error.message).toContain('Playwright manages remote debugging connection itself'); expect(error.message).toContain('Playwright manages remote debugging connection itself');
}); });
it('should open devtools when "devtools: true" option is given', async({server}) => { it('should open devtools when "devtools: true" option is given', async({browserType}) => {
const browser = await browserType.launch(Object.assign({devtools: true}, headfulOptions)); const browser = await browserType.launch(Object.assign({devtools: true}, headfulOptions));
const context = await browser.newContext(); const context = await browser.newContext();
const browserSession = await browser.newBrowserCDPSession(); const browserSession = await browser.newBrowserCDPSession();
@ -68,7 +62,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
}); });
describe('extensions', () => { describe('extensions', () => {
it('should return background pages', async() => { it('should return background pages', async({browserType}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const context = await browserType.launchPersistentContext(userDataDir, extensionOptions); const context = await browserType.launchPersistentContext(userDataDir, extensionOptions);
const backgroundPages = context.backgroundPages(); const backgroundPages = context.backgroundPages();
@ -83,7 +77,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
}); });
describe('BrowserContext', function() { describe('BrowserContext', function() {
it('should not create pages automatically', async function() { it('should not create pages automatically', async ({browserType}) => {
const browser = await browserType.launch(); const browser = await browserType.launch();
const browserSession = await browser.newBrowserCDPSession(); const browserSession = await browser.newBrowserCDPSession();
const targets = []; const targets = [];
@ -97,4 +91,3 @@ module.exports.describe = function({defaultBrowserOptions, browserType, WIN}) {
expect(targets.length).toBe(0); expect(targets.length).toBe(0);
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('../utils').testOptions(browserType);
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) {
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false
@ -25,7 +22,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
describe('OOPIF', function() { describe('OOPIF', function() {
beforeAll(async function(state) { beforeAll(async function(state) {
state.browser = await browserType.launch(Object.assign({}, defaultBrowserOptions, { state.browser = await state.browserType.launch(Object.assign({}, defaultBrowserOptions, {
args: (defaultBrowserOptions.args || []).concat(['--site-per-process']), args: (defaultBrowserOptions.args || []).concat(['--site-per-process']),
})); }));
}); });
@ -75,7 +72,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
await page.click('button'); await page.click('button');
expect(await page.evaluate(() => window.BUTTON_CLICKED)).toBe(true); expect(await page.evaluate(() => window.BUTTON_CLICKED)).toBe(true);
}); });
it('should report google.com frame with headful', async({server}) => { it('should report google.com frame with headful', async({browserType, server}) => {
// TODO: Support OOOPIF. @see https://github.com/GoogleChrome/puppeteer/issues/2548 // TODO: Support OOOPIF. @see https://github.com/GoogleChrome/puppeteer/issues/2548
// https://google.com is isolated by default in Chromium embedder. // https://google.com is isolated by default in Chromium embedder.
const browser = await browserType.launch(headfulOptions); const browser = await browserType.launch(headfulOptions);
@ -99,7 +96,6 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
await browser.close(); await browser.close();
}); });
}); });
};
async function countOOPIFs(browser) { async function countOOPIFs(browser) {
const browserSession = await browser.newBrowserCDPSession(); const browserSession = await browser.newBrowserCDPSession();

View file

@ -16,11 +16,7 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const {FFOX, CHROMIUM, WEBKIT, headless, OUTPUT_DIR} = require('../utils').testOptions(browserType);
/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({headless, OUTPUT_DIR}) {
// Printing to pdf is currently only supported in headless // Printing to pdf is currently only supported in headless
describe.fail(!headless)('Page.pdf', function() { describe.fail(!headless)('Page.pdf', function() {
@ -31,4 +27,3 @@ module.exports.describe = function({headless, OUTPUT_DIR}) {
fs.unlinkSync(outputFile); fs.unlinkSync(outputFile);
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('../utils').testOptions(browserType);
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
describe('ChromiumBrowserContext.createSession', function() { describe('ChromiumBrowserContext.createSession', function() {
it('should work', async function({page, browser, server}) { it('should work', async function({page, browser, server}) {
@ -104,4 +101,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
await session.detach(); await session.detach();
}); });
}); });
};

View file

@ -16,16 +16,12 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR, defaultBrowserOptions} = require('../utils').testOptions(browserType);
/**
* @type {ChromiumTestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, browserType, OUTPUT_DIR}) {
describe('Chromium.startTracing', function() { describe('Chromium.startTracing', function() {
beforeEach(async function(state) { beforeEach(async function(state) {
state.outputFile = path.join(OUTPUT_DIR, `trace-${state.parallelIndex}.json`); state.outputFile = path.join(OUTPUT_DIR, `trace-${state.parallelIndex}.json`);
state.browser = await browserType.launch(defaultBrowserOptions); state.browser = await state.browserType.launch(defaultBrowserOptions);
state.page = await state.browser.newPage(); state.page = await state.browser.newPage();
}); });
afterEach(async function(state) { afterEach(async function(state) {
@ -79,4 +75,3 @@ module.exports.describe = function({defaultBrowserOptions, browserType, OUTPUT_D
expect(trace.toString()).toContain('screenshot', 'Does not contain screenshot'); expect(trace.toString()).toContain('screenshot', 'Does not contain screenshot');
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.click', function() { describe('Page.click', function() {
it('should click the button', async({page, server}) => { it('should click the button', async({page, server}) => {
@ -613,4 +609,3 @@ const utils = require('./utils');
expect(await page.evaluate(() => checkbox.getAttribute('aria-checked'))).toBe('true'); expect(await page.evaluate(() => checkbox.getAttribute('aria-checked'))).toBe('true');
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT, MAC, defaultBrowserOptions} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({browserType, defaultBrowserOptions, MAC, FFOX, CHROMIUM, WEBKIT}) {
describe('BrowserContext.cookies', function() { describe('BrowserContext.cookies', function() {
it('should return no cookies in pristine browser context', async({context, page, server}) => { it('should return no cookies in pristine browser context', async({context, page, server}) => {
@ -272,7 +269,7 @@ module.exports.describe = function({browserType, defaultBrowserOptions, MAC, FFO
await context.close(); await context.close();
} }
}); });
it.slow()('should isolate cookies between launches', async({server}) => { it.slow()('should isolate cookies between launches', async({browserType, server}) => {
const browser1 = await browserType.launch(defaultBrowserOptions); const browser1 = await browserType.launch(defaultBrowserOptions);
const context1 = await browser1.newContext(); const context1 = await browser1.newContext();
await context1.addCookies([{url: server.EMPTY_PAGE, name: 'cookie-in-context-1', value: 'value', expires: Date.now() / 1000 + 10000}]); await context1.addCookies([{url: server.EMPTY_PAGE, name: 'cookie-in-context-1', value: 'value', expires: Date.now() / 1000 + 10000}]);
@ -469,4 +466,3 @@ module.exports.describe = function({browserType, defaultBrowserOptions, MAC, FFO
await anotherContext.close(); await anotherContext.close();
}); });
}); });
};

View file

@ -15,17 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
const { makeUserDataDir, removeUserDataDir } = require('./utils'); const utils = require('./utils');
const {makeUserDataDir, removeUserDataDir} = utils;
/** const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = utils.testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function ({ defaultBrowserOptions, browserType, WEBKIT }) {
describe('launchPersistentContext()', function() { describe('launchPersistentContext()', function() {
beforeEach(async state => { beforeEach(async state => {
state.userDataDir = await makeUserDataDir(); state.userDataDir = await makeUserDataDir();
state.browserContext = await browserType.launchPersistentContext(state.userDataDir, defaultBrowserOptions); state.browserContext = await state.browserType.launchPersistentContext(state.userDataDir, defaultBrowserOptions);
state.page = await state.browserContext.newPage(); state.page = await state.browserContext.newPage();
}); });
afterEach(async state => { afterEach(async state => {
@ -87,4 +84,3 @@ module.exports.describe = function ({ defaultBrowserOptions, browserType, WEBKIT
expect(await page.evaluate('document.cookie')).toBe(''); expect(await page.evaluate('document.cookie')).toBe('');
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
describe('Page.Events.Dialog', function() { describe('Page.Events.Dialog', function() {
it('should fire', async({page, server}) => { it('should fire', async({page, server}) => {
@ -62,4 +59,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
expect(result).toBe(false); expect(result).toBe(false);
}); });
}); });
};

View file

@ -16,8 +16,7 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('./utils').testOptions(browserType);
module.exports.describe = function({browserType, defaultBrowserOptions, CHROMIUM, WEBKIT, FFOX, WIN, MAC}) {
describe('Download', function() { describe('Download', function() {
beforeEach(async(state) => { beforeEach(async(state) => {
@ -97,7 +96,7 @@ module.exports.describe = function({browserType, defaultBrowserOptions, CHROMIUM
expect(fs.existsSync(path1)).toBeFalsy(); expect(fs.existsSync(path1)).toBeFalsy();
expect(fs.existsSync(path2)).toBeFalsy(); expect(fs.existsSync(path2)).toBeFalsy();
}); });
it('should delete downloads on browser gone', async ({ server }) => { it('should delete downloads on browser gone', async ({ server, browserType }) => {
const browser = await browserType.launch(defaultBrowserOptions); const browser = await browserType.launch(defaultBrowserOptions);
const page = await browser.newPage({ acceptDownloads: true }); const page = await browser.newPage({ acceptDownloads: true });
await page.setContent(`<a download=true href="${server.PREFIX}/download">download</a>`); await page.setContent(`<a download=true href="${server.PREFIX}/download">download</a>`);
@ -119,4 +118,3 @@ module.exports.describe = function({browserType, defaultBrowserOptions, CHROMIUM
expect(fs.existsSync(path.join(path1, '..'))).toBeFalsy(); expect(fs.existsSync(path.join(path1, '..'))).toBeFalsy();
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
describe('ElementHandle.boundingBox', function() { describe('ElementHandle.boundingBox', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -330,4 +326,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
expect(await page.evaluate(() => result)).toBe('some value'); expect(await page.evaluate(() => result)).toBe('some value');
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT, headless} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, headless, FFOX, CHROMIUM, WEBKIT, MAC, WIN}) {
const iPhone = playwright.devices['iPhone 6']; const iPhone = playwright.devices['iPhone 6'];
const iPhoneLandscape = playwright.devices['iPhone 6 landscape']; const iPhoneLandscape = playwright.devices['iPhone 6 landscape'];
@ -461,4 +457,3 @@ module.exports.describe = function({playwright, headless, FFOX, CHROMIUM, WEBKIT
await page2.close(); await page2.close();
}); });
}); });
};

View file

@ -17,11 +17,7 @@
const utils = require('./utils'); const utils = require('./utils');
const path = require('path'); const path = require('path');
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
describe('Page.evaluate', function() { describe('Page.evaluate', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -454,4 +450,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
expect(constructorName).toBe('HTMLIFrameElement'); expect(constructorName).toBe('HTMLIFrameElement');
}); });
}); });
};

View file

@ -17,13 +17,9 @@
const path = require('path'); const path = require('path');
const {spawn, execSync} = require('child_process'); const {spawn, execSync} = require('child_process');
const {FFOX, CHROMIUM, WEBKIT, WIN, playwrightPath, defaultBrowserOptions} = require('./utils').testOptions(browserType);
/** async function testSignal(browserType, action, exitOnClose) {
* @type {TestSuite}
*/
module.exports.describe = function({browserType, playwrightPath, defaultBrowserOptions, WIN, FFOX, CHROMIUM, WEBKIT}) {
async function testSignal(action, exitOnClose) {
const options = Object.assign({}, defaultBrowserOptions, { const options = Object.assign({}, defaultBrowserOptions, {
// Disable DUMPIO to cleanly read stdout. // Disable DUMPIO to cleanly read stdout.
dumpio: false, dumpio: false,
@ -66,15 +62,15 @@ module.exports.describe = function({browserType, playwrightPath, defaultBrowserO
} }
describe('Fixtures', function() { describe('Fixtures', function() {
it.slow()('should dump browser process stderr', async({server}) => { it.slow()('should dump browser process stderr', async({browserType}) => {
let dumpioData = ''; let dumpioData = '';
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, browserType.name()]); const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, browserType.name()]);
res.stdout.on('data', data => dumpioData += data.toString('utf8')); res.stdout.on('data', data => dumpioData += data.toString('utf8'));
await new Promise(resolve => res.on('close', resolve)); await new Promise(resolve => res.on('close', resolve));
expect(dumpioData).toContain('message from dumpio'); expect(dumpioData).toContain('message from dumpio');
}); });
it.slow()('should close the browser when the node process closes', async () => { it.slow()('should close the browser when the node process closes', async ({browserType}) => {
const result = await testSignal(child => { const result = await testSignal(browserType, child => {
if (WIN) if (WIN)
execSync(`taskkill /pid ${child.pid} /T /F`); execSync(`taskkill /pid ${child.pid} /T /F`);
else else
@ -87,38 +83,38 @@ module.exports.describe = function({browserType, playwrightPath, defaultBrowserO
describe.skip(WIN)('signals', () => { describe.skip(WIN)('signals', () => {
// Cannot reliably send signals on Windows. // Cannot reliably send signals on Windows.
it.slow()('should report browser close signal', async () => { it.slow()('should report browser close signal', async ({browserType}) => {
const result = await testSignal((child, browserPid) => process.kill(browserPid), true); const result = await testSignal(browserType, (child, browserPid) => process.kill(browserPid), true);
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.browserExitCode).toBe('null'); expect(result.browserExitCode).toBe('null');
expect(result.browserSignal).toBe('SIGTERM'); expect(result.browserSignal).toBe('SIGTERM');
}); });
it.slow()('should report browser close signal 2', async (state, test) => { it.slow()('should report browser close signal 2', async ({browserType}) => {
const result = await testSignal((child, browserPid) => process.kill(browserPid, 'SIGKILL'), true); const result = await testSignal(browserType, (child, browserPid) => process.kill(browserPid, 'SIGKILL'), true);
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.browserExitCode).toBe('null'); expect(result.browserExitCode).toBe('null');
expect(result.browserSignal).toBe('SIGKILL'); expect(result.browserSignal).toBe('SIGKILL');
}); });
it.slow()('should close the browser on SIGINT', async () => { it.slow()('should close the browser on SIGINT', async ({browserType}) => {
const result = await testSignal(child => process.kill(child.pid, 'SIGINT')); const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGINT'));
expect(result.exitCode).toBe(130); expect(result.exitCode).toBe(130);
expect(result.browserExitCode).toBe('0'); expect(result.browserExitCode).toBe('0');
expect(result.browserSignal).toBe('null'); expect(result.browserSignal).toBe('null');
}); });
it.slow()('should close the browser on SIGTERM', async () => { it.slow()('should close the browser on SIGTERM', async ({browserType}) => {
const result = await testSignal(child => process.kill(child.pid, 'SIGTERM')); const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGTERM'));
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.browserExitCode).toBe('0'); expect(result.browserExitCode).toBe('0');
expect(result.browserSignal).toBe('null'); expect(result.browserSignal).toBe('null');
}); });
it.slow()('should close the browser on SIGHUP', async () => { it.slow()('should close the browser on SIGHUP', async ({browserType}) => {
const result = await testSignal(child => process.kill(child.pid, 'SIGHUP')); const result = await testSignal(browserType, child => process.kill(child.pid, 'SIGHUP'));
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
expect(result.browserExitCode).toBe('0'); expect(result.browserExitCode).toBe('0');
expect(result.browserSignal).toBe('null'); expect(result.browserSignal).toBe('null');
}); });
it.slow()('should kill the browser on double SIGINT', async () => { it.slow()('should kill the browser on double SIGINT', async ({browserType}) => {
const result = await testSignal(child => { const result = await testSignal(browserType, child => {
process.kill(child.pid, 'SIGINT'); process.kill(child.pid, 'SIGINT');
process.kill(child.pid, 'SIGINT'); process.kill(child.pid, 'SIGINT');
}); });
@ -126,8 +122,8 @@ module.exports.describe = function({browserType, playwrightPath, defaultBrowserO
// TODO: ideally, we would expect the SIGKILL on the browser from // TODO: ideally, we would expect the SIGKILL on the browser from
// force kill, but that's racy with sending two signals. // force kill, but that's racy with sending two signals.
}); });
it.slow()('should kill the browser on SIGINT + SIGTERM', async () => { it.slow()('should kill the browser on SIGINT + SIGTERM', async ({browserType}) => {
const result = await testSignal(child => { const result = await testSignal(browserType, child => {
process.kill(child.pid, 'SIGINT'); process.kill(child.pid, 'SIGINT');
process.kill(child.pid, 'SIGTERM'); process.kill(child.pid, 'SIGTERM');
}); });
@ -135,8 +131,8 @@ module.exports.describe = function({browserType, playwrightPath, defaultBrowserO
// TODO: ideally, we would expect the SIGKILL on the browser from // TODO: ideally, we would expect the SIGKILL on the browser from
// force kill, but that's racy with sending two signals. // force kill, but that's racy with sending two signals.
}); });
it.slow()('should kill the browser on SIGTERM + SIGINT', async () => { it.slow()('should kill the browser on SIGTERM + SIGINT', async ({browserType}) => {
const result = await testSignal(child => { const result = await testSignal(browserType, child => {
process.kill(child.pid, 'SIGTERM'); process.kill(child.pid, 'SIGTERM');
process.kill(child.pid, 'SIGINT'); process.kill(child.pid, 'SIGINT');
}); });
@ -146,4 +142,3 @@ module.exports.describe = function({browserType, playwrightPath, defaultBrowserO
}); });
}); });
}); });
};

View file

@ -14,10 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({}) {
describe('Page.focus', function() { describe('Page.focus', function() {
it('should work', async function({page, server}) { it('should work', async function({page, server}) {
@ -48,4 +45,3 @@ module.exports.describe = function({}) {
expect(blurred).toBe(true); expect(blurred).toBe(true);
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
describe('Frame.evaluateHandle', function() { describe('Frame.evaluateHandle', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -234,4 +230,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT}) {
expect(frame1).not.toBe(frame2); expect(frame1).not.toBe(frame2);
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function ({ FFOX, WEBKIT }) {
describe('Overrides.setGeolocation', function() { describe('Overrides.setGeolocation', function() {
it('should work', async({page, server, context}) => { it('should work', async({page, server, context}) => {
@ -121,4 +118,3 @@ module.exports.describe = function ({ FFOX, WEBKIT }) {
expect(geolocation).toEqual({ longitude: 10, latitude: 10 }); expect(geolocation).toEqual({ longitude: 10, latitude: 10 });
}); });
}); });
};

View file

@ -14,12 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
const { makeUserDataDir, removeUserDataDir } = require('./utils'); const utils = require('./utils');
const { makeUserDataDir, removeUserDataDir } = utils;
/** const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions} = utils.testOptions(browserType);
* @type {TestSuite}
*/
module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CHROMIUM, WEBKIT, WIN}) {
const headfulOptions = Object.assign({}, defaultBrowserOptions, { const headfulOptions = Object.assign({}, defaultBrowserOptions, {
headless: false headless: false
@ -29,7 +26,7 @@ module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CH
}); });
describe('Headful', function() { describe('Headful', function() {
it('should have default url when launching browser', async function() { it('should have default url when launching browser', async ({browserType}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions); const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions);
const urls = browserContext.pages().map(page => page.url()); const urls = browserContext.pages().map(page => page.url());
@ -37,7 +34,7 @@ module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CH
await browserContext.close(); await browserContext.close();
await removeUserDataDir(userDataDir); await removeUserDataDir(userDataDir);
}); });
it.slow().fail(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({server}) => { it.slow().fail(WIN && CHROMIUM)('headless should be able to read cookies written by headful', async({browserType, server}) => {
// see https://github.com/microsoft/playwright/issues/717 // see https://github.com/microsoft/playwright/issues/717
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
// Write a cookie in headful chrome // Write a cookie in headful chrome
@ -56,7 +53,7 @@ module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CH
await removeUserDataDir(userDataDir); await removeUserDataDir(userDataDir);
expect(cookie).toBe('foo=true'); expect(cookie).toBe('foo=true');
}); });
it.slow()('should close browser with beforeunload page', async({server}) => { it.slow()('should close browser with beforeunload page', async({browserType, server}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions); const browserContext = await browserType.launchPersistentContext(userDataDir, headfulOptions);
const page = await browserContext.newPage(); const page = await browserContext.newPage();
@ -68,4 +65,3 @@ module.exports.describe = function({browserType, defaultBrowserOptions, FFOX, CH
await removeUserDataDir(userDataDir); await removeUserDataDir(userDataDir);
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {BrowserTestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('ignoreHTTPSErrors', function() { describe('ignoreHTTPSErrors', function() {
it('should work', async({browser, httpsServer}) => { it('should work', async({browser, httpsServer}) => {
@ -64,4 +61,3 @@ module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHR
await context.close(); await context.close();
}); });
}); });
};

View file

@ -20,11 +20,7 @@ const fs = require('fs');
const formidable = require('formidable'); const formidable = require('formidable');
const FILE_TO_UPLOAD = path.join(__dirname, '/assets/file-to-upload.txt'); const FILE_TO_UPLOAD = path.join(__dirname, '/assets/file-to-upload.txt');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('input', function() { describe('input', function() {
it('should upload the file', async({page, server}) => { it('should upload the file', async({page, server}) => {
@ -243,4 +239,3 @@ module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
expect(multiple).toBe(true); expect(multiple).toBe(true);
}); });
}); });
};

View file

@ -18,13 +18,8 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const { helper } = require('../lib/helper'); const { helper } = require('../lib/helper');
const utils = require('./utils');
const vm = require('vm'); const vm = require('vm');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.route', function() { describe('Page.route', function() {
it('should intercept', async({page, server}) => { it('should intercept', async({page, server}) => {
@ -568,4 +563,3 @@ module.exports.describe = function({defaultBrowserOptions, playwright, FFOX, CHR
expect(intercepted).toBe(true); expect(intercepted).toBe(true);
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({CHROMIUM, FFOX, WEBKIT}) {
describe('Page.evaluateHandle', function() { describe('Page.evaluateHandle', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -274,4 +271,3 @@ module.exports.describe = function({CHROMIUM, FFOX, WEBKIT}) {
expect((await page.evaluateHandle('new Proxy({}, {})')).toString()).toBe('JSHandle@proxy'); expect((await page.evaluateHandle('new Proxy({}, {})')).toString()).toBe('JSHandle@proxy');
}); });
}); });
};

View file

@ -16,12 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const os = require('os'); const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
describe('Keyboard', function() { describe('Keyboard', function() {
it('should type into a textarea', async({page, server}) => { it('should type into a textarea', async({page, server}) => {
@ -309,4 +304,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
expect(await page.evaluate('lastKey.key')).toBe('a'); expect(await page.evaluate('lastKey.key')).toBe('a');
}) })
}); });
};

View file

@ -18,16 +18,12 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const utils = require('./utils'); const utils = require('./utils');
const { makeUserDataDir, removeUserDataDir } = require('./utils'); const { makeUserDataDir, removeUserDataDir } = utils;
const {FFOX, CHROMIUM, WEBKIT, WIN, defaultBrowserOptions, playwrightPath} = utils.testOptions(browserType);
/**
* @type {TestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, playwright, browserType, playwrightPath, CHROMIUM, FFOX, WEBKIT, WIN}) {
describe('Playwright', function() { describe('Playwright', function() {
describe('browserType.launch', function() { describe('browserType.launch', function() {
it('should reject all promises when browser is closed', async() => { it('should reject all promises when browser is closed', async({browserType}) => {
const browser = await browserType.launch(defaultBrowserOptions); const browser = await browserType.launch(defaultBrowserOptions);
const page = await (await browser.newContext()).newPage(); const page = await (await browser.newContext()).newPage();
let error = null; let error = null;
@ -36,19 +32,19 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await neverResolves; await neverResolves;
expect(error.message).toContain('Protocol error'); expect(error.message).toContain('Protocol error');
}); });
it('should throw if userDataDir option is passed', async() => { it('should throw if userDataDir option is passed', async({browserType}) => {
let waitError = null; let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'}); const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
await browserType.launch(options).catch(e => waitError = e); await browserType.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('launchPersistentContext'); expect(waitError.message).toContain('launchPersistentContext');
}); });
it('should throw if page argument is passed', async() => { it('should throw if page argument is passed', async({browserType}) => {
let waitError = null; let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] }); const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] });
await browserType.launch(options).catch(e => waitError = e); await browserType.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('can not specify page'); expect(waitError.message).toContain('can not specify page');
}); });
it('should reject if executable path is invalid', async({server}) => { it('should reject if executable path is invalid', async({browserType}) => {
let waitError = null; let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'}); const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
await browserType.launch(options).catch(e => waitError = e); await browserType.launch(options).catch(e => waitError = e);
@ -57,7 +53,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.launchPersistentContext', function() { describe('browserType.launchPersistentContext', function() {
it('should have default URL when launching browser', async function() { it('should have default URL when launching browser', async ({browserType}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions); const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);
const urls = browserContext.pages().map(page => page.url()); const urls = browserContext.pages().map(page => page.url());
@ -65,7 +61,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserContext.close(); await browserContext.close();
await removeUserDataDir(userDataDir); await removeUserDataDir(userDataDir);
}); });
it('should have custom URL when launching browser', async function({server}) { it('should have custom URL when launching browser', async ({browserType, server}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const options = Object.assign({}, defaultBrowserOptions); const options = Object.assign({}, defaultBrowserOptions);
options.args = [server.EMPTY_PAGE].concat(options.args || []); options.args = [server.EMPTY_PAGE].concat(options.args || []);
@ -83,12 +79,12 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.launchServer', function() { describe('browserType.launchServer', function() {
it('should return child_process instance', async () => { it('should return child_process instance', async ({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
expect(browserServer.process().pid).toBeGreaterThan(0); expect(browserServer.process().pid).toBeGreaterThan(0);
await browserServer.close(); await browserServer.close();
}); });
it('should fire close event', async () => { it('should fire close event', async ({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
await Promise.all([ await Promise.all([
new Promise(f => browserServer.on('close', f)), new Promise(f => browserServer.on('close', f)),
@ -98,7 +94,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.executablePath', function() { describe('browserType.executablePath', function() {
it('should work', async({server}) => { it('should work', async({browserType}) => {
const executablePath = browserType.executablePath(); const executablePath = browserType.executablePath();
expect(fs.existsSync(executablePath)).toBe(true); expect(fs.existsSync(executablePath)).toBe(true);
expect(fs.realpathSync(executablePath)).toBe(executablePath); expect(fs.realpathSync(executablePath)).toBe(executablePath);
@ -106,7 +102,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.name', function() { describe('browserType.name', function() {
it('should work', async({server}) => { it('should work', async({browserType}) => {
if (WEBKIT) if (WEBKIT)
expect(browserType.name()).toBe('webkit'); expect(browserType.name()).toBe('webkit');
else if (FFOX) else if (FFOX)
@ -133,7 +129,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('Browser.isConnected', () => { describe('Browser.isConnected', () => {
it('should set the browser connected state', async () => { it('should set the browser connected state', async ({browserType}) => {
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(remote.isConnected()).toBe(true); expect(remote.isConnected()).toBe(true);
@ -142,7 +138,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should throw when used after isConnected returns false', async({server}) => { it('should throw when used after isConnected returns false', async({browserType}) => {
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage(); const page = await remote.newPage();
@ -157,7 +153,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('Browser.disconnect', function() { describe('Browser.disconnect', function() {
it('should reject navigation when browser closes', async({server}) => { it('should reject navigation when browser closes', async({browserType, server}) => {
server.setRoute('/one-style.css', () => {}); server.setRoute('/one-style.css', () => {});
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -170,7 +166,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should reject waitForSelector when browser closes', async({server}) => { it('should reject waitForSelector when browser closes', async({browserType, server}) => {
server.setRoute('/empty.html', () => {}); server.setRoute('/empty.html', () => {});
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -186,7 +182,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should throw if used after disconnect', async({server}) => { it('should throw if used after disconnect', async({browserType}) => {
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const page = await remote.newPage(); const page = await remote.newPage();
@ -196,7 +192,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should emit close events on pages and contexts', async({server}) => { it('should emit close events on pages and contexts', async({browserType}) => {
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const context = await remote.newContext(); const context = await remote.newContext();
@ -212,7 +208,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('Browser.close', function() { describe('Browser.close', function() {
it('should terminate network waiters', async({server}) => { it('should terminate network waiters', async({browserType, server}) => {
const browserServer = await browserType.launchServer({...defaultBrowserOptions }); const browserServer = await browserType.launchServer({...defaultBrowserOptions });
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const newPage = await remote.newPage(); const newPage = await remote.newPage();
@ -227,7 +223,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
expect(message).not.toContain('Timeout'); expect(message).not.toContain('Timeout');
} }
}); });
it('should fire close event for all contexts', async(state, test) => { it('should fire close event for all contexts', async({browserType}) => {
const browser = await browserType.launch(defaultBrowserOptions); const browser = await browserType.launch(defaultBrowserOptions);
const context = await browser.newContext(); const context = await browser.newContext();
let closed = false; let closed = false;
@ -238,7 +234,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.launch |webSocket| option', function() { describe('browserType.launch |webSocket| option', function() {
it('should support the webSocket option', async() => { it('should support the webSocket option', async({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browserContext = await browser.newContext(); const browserContext = await browser.newContext();
@ -251,7 +247,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should fire "disconnected" when closing with webSocket', async() => { it('should fire "disconnected" when closing with webSocket', async({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve)); const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve));
@ -261,7 +257,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.connect', function() { describe('browserType.connect', function() {
it.slow()('should be able to reconnect to a browser', async({server}) => { it.slow()('should be able to reconnect to a browser', async({browserType, server}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
{ {
const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -283,7 +279,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
}); });
describe('browserType.launchPersistentContext', function() { describe('browserType.launchPersistentContext', function() {
it('userDataDir option', async({server}) => { it('userDataDir option', async({browserType}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const options = Object.assign(defaultBrowserOptions); const options = Object.assign(defaultBrowserOptions);
const browserContext = await browserType.launchPersistentContext(userDataDir, options); const browserContext = await browserType.launchPersistentContext(userDataDir, options);
@ -295,7 +291,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
// This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778
await removeUserDataDir(userDataDir); await removeUserDataDir(userDataDir);
}); });
it.slow()('userDataDir option should restore state', async({server}) => { it.slow()('userDataDir option should restore state', async({browserType, server}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions); const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);
const page = await browserContext.newPage(); const page = await browserContext.newPage();
@ -321,7 +317,7 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await removeUserDataDir(userDataDir2); await removeUserDataDir(userDataDir2);
}); });
// See https://github.com/microsoft/playwright/issues/717 // See https://github.com/microsoft/playwright/issues/717
it.slow().fail(WIN && CHROMIUM)('userDataDir option should restore cookies', async({server}) => { it.slow().fail(WIN && CHROMIUM)('userDataDir option should restore cookies', async({browserType, server}) => {
const userDataDir = await makeUserDataDir(); const userDataDir = await makeUserDataDir();
const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions); const browserContext = await browserType.launchPersistentContext(userDataDir, defaultBrowserOptions);
const page = await browserContext.newPage(); const page = await browserContext.newPage();
@ -347,4 +343,3 @@ module.exports.describe = function({defaultBrowserOptions, playwright, browserTy
await removeUserDataDir(userDataDir2); await removeUserDataDir(userDataDir2);
}); });
}); });
};

View file

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
function dimensions() { function dimensions() {
const rect = document.querySelector('textarea').getBoundingClientRect(); const rect = document.querySelector('textarea').getBoundingClientRect();
return { return {
@ -25,11 +27,6 @@ function dimensions() {
}; };
} }
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
describe('Mouse', function() { describe('Mouse', function() {
it('should click the document', async({page, server}) => { it('should click the document', async({page, server}) => {
await page.evaluate(() => { await page.evaluate(() => {
@ -156,4 +153,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, MAC}) {
}) })
}); });
}); });
};

View file

@ -15,15 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
const utils = require('./utils'); const {FFOX, CHROMIUM, WEBKIT, defaultBrowserOptions} = require('./utils').testOptions(browserType);
/**
* @type {TestSuite}
*/
module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CHROMIUM, WEBKIT}) {
describe('BrowserContext', function() { describe('BrowserContext', function() {
it('should work across sessions', async () => { it('should work across sessions', async ({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
expect(browser1.contexts().length).toBe(0); expect(browser1.contexts().length).toBe(0);
@ -46,7 +41,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
}); });
describe('Browser.Events.disconnected', function() { describe('Browser.Events.disconnected', function() {
it.slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async () => { it.slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async ({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
const originalBrowser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const originalBrowser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const wsEndpoint = browserServer.wsEndpoint(); const wsEndpoint = browserServer.wsEndpoint();
@ -82,7 +77,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
}); });
describe('browserType.connect', function() { describe('browserType.connect', function() {
it('should be able to connect multiple times to the same browser', async({server}) => { it('should be able to connect multiple times to the same browser', async({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -96,7 +91,7 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
await browserServer._checkLeaks(); await browserServer._checkLeaks();
await browserServer.close(); await browserServer.close();
}); });
it('should not be able to close remote browser', async() => { it('should not be able to close remote browser', async({browserType}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions); const browserServer = await browserType.launchServer(defaultBrowserOptions);
{ {
const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() });
@ -112,4 +107,3 @@ module.exports.describe = function({defaultBrowserOptions, browserType, FFOX, CH
await browserServer.close(); await browserServer.close();
}); });
}); });
};

View file

@ -18,11 +18,7 @@
const utils = require('./utils'); const utils = require('./utils');
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');
const {FFOX, CHROMIUM, WEBKIT, MAC, WIN} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.goto', function() { describe('Page.goto', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -1081,5 +1077,3 @@ module.exports.describe = function({playwright, MAC, WIN, FFOX, CHROMIUM, WEBKIT
expect(errorMessage).toContain('SSL_ERROR_UNKNOWN'); expect(errorMessage).toContain('SSL_ERROR_UNKNOWN');
} }
} }
};

View file

@ -18,11 +18,7 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT, MAC, WIN} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.Events.Request', function() { describe('Page.Events.Request', function() {
it('should fire for navigation requests', async({page, server}) => { it('should fire for navigation requests', async({page, server}) => {
@ -369,4 +365,3 @@ module.exports.describe = function({MAC, WIN, FFOX, CHROMIUM, WEBKIT}) {
expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.'); expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.');
}); });
}); });
};

View file

@ -17,11 +17,7 @@
const path = require('path'); const path = require('path');
const vm = require('vm'); const vm = require('vm');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.close', function() { describe('Page.close', function() {
it('should reject all promises when page is closed', async({context}) => { it('should reject all promises when page is closed', async({context}) => {
@ -1127,4 +1123,3 @@ module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
expect(await frame.evaluate(() => document.querySelector('textarea').value)).toBe('a'); expect(await frame.evaluate(() => document.querySelector('textarea').value)).toBe('a');
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({WEBKIT, FFOX}) {
// Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API) // Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API)
describe.skip(WEBKIT)('Permissions', function() { describe.skip(WEBKIT)('Permissions', function() {
@ -123,4 +120,3 @@ module.exports.describe = function({WEBKIT, FFOX}) {
await otherContext.close(); await otherContext.close();
}); });
}); });
};

View file

@ -80,9 +80,11 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
const playwrightEnvironment = new Environment('Playwright'); const playwrightEnvironment = new Environment('Playwright');
playwrightEnvironment.beforeAll(async state => { playwrightEnvironment.beforeAll(async state => {
state.playwright = playwright; state.playwright = playwright;
global.playwright = playwright;
}); });
playwrightEnvironment.afterAll(async state => { playwrightEnvironment.afterAll(async state => {
delete state.playwright; delete state.playwright;
delete global.playwright;
}); });
for (const product of products) { for (const product of products) {
@ -143,21 +145,6 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
state.page = null; state.page = null;
}); });
function loadTests(modulePath) {
const testOptions = {
...require('./utils').testOptions(global.browserType),
playwright: global.playwright,
browserType: global.browserType,
};
const module = require(modulePath);
if (typeof module.describe === 'function')
describe('', module.describe, testOptions);
if (typeof module.fdescribe === 'function')
fdescribe('', module.fdescribe, testOptions);
if (typeof module.xdescribe === 'function')
xdescribe('', module.xdescribe, testOptions);
}
testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment. testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment.
testRunner.collector().useEnvironment(playwrightEnvironment); testRunner.collector().useEnvironment(playwrightEnvironment);
@ -177,71 +164,66 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
// Page-level tests that are given a browser, a context and a page. // Page-level tests that are given a browser, a context and a page.
// Each test is launched in a new browser context. // Each test is launched in a new browser context.
describe('[Accessibility]', () => loadTests('./accessibility.spec.js')); require('./accessibility.spec.js');
describe('[Driver]', () => { require('./autowaiting.spec.js');
loadTests('./autowaiting.spec.js'); require('./click.spec.js');
loadTests('./click.spec.js'); require('./cookies.spec.js');
loadTests('./cookies.spec.js'); require('./dialog.spec.js');
loadTests('./dialog.spec.js'); require('./download.spec.js');
loadTests('./download.spec.js'); require('./elementhandle.spec.js');
loadTests('./elementhandle.spec.js'); require('./emulation.spec.js');
loadTests('./emulation.spec.js'); require('./evaluation.spec.js');
loadTests('./evaluation.spec.js'); require('./frame.spec.js');
loadTests('./frame.spec.js'); require('./focus.spec.js');
loadTests('./focus.spec.js'); require('./input.spec.js');
loadTests('./input.spec.js'); require('./jshandle.spec.js');
loadTests('./jshandle.spec.js'); require('./keyboard.spec.js');
loadTests('./keyboard.spec.js'); require('./mouse.spec.js');
loadTests('./mouse.spec.js'); require('./navigation.spec.js');
loadTests('./navigation.spec.js'); require('./network.spec.js');
loadTests('./network.spec.js'); require('./page.spec.js');
loadTests('./page.spec.js'); require('./queryselector.spec.js');
loadTests('./queryselector.spec.js'); require('./screenshot.spec.js');
loadTests('./screenshot.spec.js'); require('./waittask.spec.js');
loadTests('./waittask.spec.js'); require('./interception.spec.js');
loadTests('./interception.spec.js'); require('./geolocation.spec.js');
loadTests('./geolocation.spec.js'); require('./workers.spec.js');
loadTests('./workers.spec.js'); require('./capabilities.spec.js');
loadTests('./capabilities.spec.js'); require('./permissions.spec.js');
});
describe('[Permissions]', () => {
loadTests('./permissions.spec.js');
});
describe.skip(product !== 'Chromium')('[Chromium]', () => { describe.skip(product !== 'Chromium')('[Chromium]', () => {
loadTests('./chromium/chromium.spec.js'); require('./chromium/chromium.spec.js');
loadTests('./chromium/coverage.spec.js'); require('./chromium/coverage.spec.js');
loadTests('./chromium/pdf.spec.js'); require('./chromium/pdf.spec.js');
loadTests('./chromium/session.spec.js'); require('./chromium/session.spec.js');
}); });
}); });
// Browser-level tests that are given a browser. // Browser-level tests that are given a browser.
describe('[Driver]', () => { describe('[Driver]', () => {
loadTests('./browser.spec.js'); require('./browser.spec.js');
loadTests('./browsercontext.spec.js'); require('./browsercontext.spec.js');
loadTests('./ignorehttpserrors.spec.js'); require('./ignorehttpserrors.spec.js');
loadTests('./popup.spec.js'); require('./popup.spec.js');
}); });
}); });
// Top-level tests that launch Browser themselves. // Top-level tests that launch Browser themselves.
describe('[Driver]', () => { describe('[Driver]', () => {
loadTests('./defaultbrowsercontext.spec.js'); require('./defaultbrowsercontext.spec.js');
loadTests('./fixtures.spec.js'); require('./fixtures.spec.js');
loadTests('./launcher.spec.js'); require('./launcher.spec.js');
loadTests('./headful.spec.js'); require('./headful.spec.js');
loadTests('./multiclient.spec.js'); require('./multiclient.spec.js');
}); });
describe.skip(product !== 'Chromium')('[Chromium]', () => { describe.skip(product !== 'Chromium')('[Chromium]', () => {
loadTests('./chromium/launcher.spec.js'); require('./chromium/launcher.spec.js');
loadTests('./chromium/oopif.spec.js'); require('./chromium/oopif.spec.js');
loadTests('./chromium/tracing.spec.js'); require('./chromium/tracing.spec.js');
}); });
if (process.env.COVERAGE) require('./apicoverage.spec.js');
loadTests('./apicoverage.spec.js');
delete global.browserType; delete global.browserType;
delete global.playwright; delete global.playwright;

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
module.exports.describe = function({playwright, CHROMIUM, WEBKIT, FFOX}) { const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
describe('Link navigation', function() { describe('Link navigation', function() {
it('should inherit user agent from browser context', async function({browser, server}) { it('should inherit user agent from browser context', async function({browser, server}) {
@ -333,5 +333,3 @@ module.exports.describe = function({playwright, CHROMIUM, WEBKIT, FFOX}) {
expect(badSecondPopup).toBe(false); expect(badSecondPopup).toBe(false);
}); });
}); });
};

View file

@ -17,11 +17,7 @@
const path = require('path'); const path = require('path');
const zsSelectorEngineSource = require('../lib/generated/zsSelectorEngineSource'); const zsSelectorEngineSource = require('../lib/generated/zsSelectorEngineSource');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.$eval', function() { describe('Page.$eval', function() {
it('should work with css selector', async({page, server}) => { it('should work with css selector', async({page, server}) => {
@ -650,4 +646,3 @@ module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
expect(error.message).toBe('"css" is a predefined selector engine'); expect(error.message).toBe('"css" is a predefined selector engine');
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX }) {
describe('Page.screenshot', function() { describe('Page.screenshot', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -480,4 +477,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX }) {
await context.close(); await context.close();
}); });
}); });
};

View file

@ -16,11 +16,7 @@
*/ */
const utils = require('./utils'); const utils = require('./utils');
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
/**
* @type {PageTestSuite}
*/
module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
describe('Page.waitFor', function() { describe('Page.waitFor', function() {
it('should wait for selector', async({page, server}) => { it('should wait for selector', async({page, server}) => {
@ -463,5 +459,3 @@ module.exports.describe = function({playwright, FFOX, CHROMIUM, WEBKIT}) {
expect(await page.evaluate(x => x.textContent, await waitForXPath)).toBe('some text'); expect(await page.evaluate(x => x.textContent, await waitForXPath)).toBe('some text');
}); });
}); });
};

View file

@ -15,10 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
* @type {PageTestSuite}
*/
module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
describe('Workers', function() { describe('Workers', function() {
it('Page.workers', async function({page, server}) { it('Page.workers', async function({page, server}) {
@ -137,4 +134,3 @@ module.exports.describe = function({FFOX, CHROMIUM, WEBKIT, LINUX}) {
await context.close(); await context.close();
}); });
}); });
};