Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: add missing tests (#965)
Andrey Lushnikovbfaf191c9827
diff --git a/src/page.ts b/src/page.tsindex 3e899647f5..f0f6bfbb24 100644--- a/src/page.ts+++ b/src/page.ts@@ -216,7 +216,7 @@ export class Page extends platform.EventEmitter {}async $wait(selector: string, options?: types.TimeoutOptions & { visibility?: types.Visibility }): Promise<dom.ElementHandle<Element> | null> {- return this.waitForSelector(selector, options);+ return this.mainFrame().$wait(selector, options);}evaluateHandle: types.EvaluateHandle = async (pageFunction, ...args) => {diff --git a/test/features/permissions.spec.js b/test/features/permissions.spec.jsindex ea531eeda5..86d0148903 100644--- a/test/features/permissions.spec.js+++ b/test/features/permissions.spec.js@@ -27,39 +27,39 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;// Permissions API is not implemented in WebKit (see https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API)- describe('Permissions', function() {+ describe.skip(WEBKIT)('Permissions', function() {function getPermission(page, name) {return page.evaluate(name => navigator.permissions.query({name}).then(result => result.state), name);}- it.skip(WEBKIT)('should be prompt by default', async({page, server, context}) => {+ it('should be prompt by default', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);expect(await getPermission(page, 'geolocation')).toBe('prompt');});- it.skip(WEBKIT)('should deny permission when not listed', async({page, server, context}) => {+ it('should deny permission when not listed', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);await context.setPermissions(server.EMPTY_PAGE, []);expect(await getPermission(page, 'geolocation')).toBe('denied');});- it.skip(WEBKIT)('should fail when bad permission is given', async({page, server, context}) => {+ it('should fail when bad permission is given', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);let error = {};await context.setPermissions(server.EMPTY_PAGE, ['foo']).catch(e => error = e);expect(error.message).toBe('Unknown permission: foo');});- it.skip(WEBKIT)('should grant permission when listed', async({page, server, context}) => {+ it('should grant permission when listed', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);expect(await getPermission(page, 'geolocation')).toBe('granted');});- it.skip(WEBKIT)('should reset permissions', async({page, server, context}) => {+ it('should reset permissions', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);await context.setPermissions(server.EMPTY_PAGE, ['geolocation']);expect(await getPermission(page, 'geolocation')).toBe('granted');await context.clearPermissions();expect(await getPermission(page, 'geolocation')).toBe('prompt');});- it.skip(WEBKIT)('should trigger permission onchange', async({page, server, context}) => {+ it('should trigger permission onchange', async({page, server, context}) => {await page.goto(server.EMPTY_PAGE);await page.evaluate(() => {window['events'] = [];@@ -78,7 +78,7 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {await context.clearPermissions();expect(await page.evaluate(() => window['events'])).toEqual(['prompt', 'denied', 'granted', 'prompt']);});- it.skip(WEBKIT)('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {+ it('should isolate permissions between browser contexs', async({page, server, context, newContext}) => {await page.goto(server.EMPTY_PAGE);const otherContext = await newContext();const otherPage = await otherContext.newPage();diff --git a/test/launcher.spec.js b/test/launcher.spec.jsindex 08e87b7518..c1bdb0af0f 100644--- a/test/launcher.spec.js+++ b/test/launcher.spec.js@@ -45,6 +45,9 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, pawait playwright.launch(options).catch(e => waitError = e);expect(waitError.message).toContain('Failed to launch');});+ });++ describe('Playwright.launchPersistent', function() {it('should have default URL when launching browser', async function() {const userDataDir = await makeUserDataDir();const browserContext = await playwright.launchPersistent(userDataDir, defaultBrowserOptions);@@ -68,12 +71,20 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, pawait browserContext.close();await removeUserDataDir(userDataDir);});+ });++ describe('Playwright.launchServer', function() {it('should return child_process instance', async () => {- const userDataDir = await makeUserDataDir();- const browserServer = await playwright.launchServer(userDataDir, defaultBrowserOptions);+ const browserServer = await playwright.launchServer(defaultBrowserOptions);expect(browserServer.process().pid).toBeGreaterThan(0);await browserServer.close();- await removeUserDataDir(userDataDir);+ });+ it('should fire close event', async () => {+ const browserServer = await playwright.launchServer(defaultBrowserOptions);+ await Promise.all([+ utils.waitEvent(browserServer, 'close'),+ browserServer.close(),+ ]);});});diff --git a/test/test.js b/test/test.jsindex 29406e637a..688735ed08 100644--- a/test/test.js+++ b/test/test.js@@ -80,18 +80,22 @@ beforeEach(async({server, httpsServer}) => {const products = ['WebKit', 'Firefox', 'Chromium'];let product;let events;+let missingCoverage;if (process.env.BROWSER === 'firefox') {product = 'Firefox';events = {...require('../lib/events').Events,...require('../lib/chromium/events').Events,};+ missingCoverage = ['browserContext.setGeolocation', 'elementHandle.scrollIntoViewIfNeeded', 'page.setOfflineMode'];} else if (process.env.BROWSER === 'webkit') {product = 'WebKit';events = require('../lib/events').Events;+ missingCoverage = ['browserContext.clearPermissions'];} else {product = 'Chromium';events = require('../lib/events').Events;+ missingCoverage = [];}describe(product, () => {@@ -108,7 +112,7 @@ describe(product, () => {return;filteredApi[name] = api[name];});- utils.recordAPICoverage(testRunner, filteredApi, events);+ utils.recordAPICoverage(testRunner, filteredApi, events, missingCoverage);}});diff --git a/test/utils.js b/test/utils.jsindex 13e5ad0141..2d5eca71c7 100644--- a/test/utils.js+++ b/test/utils.js@@ -79,18 +79,24 @@ const utils = module.exports = {return promisified;},- recordAPICoverage: function(testRunner, api, events) {+ recordAPICoverage: function(testRunner, api, events, ignoredMethodsArray = []) {const coverage = new Map();+ const ignoredMethods = new Set(ignoredMethodsArray);for (const [className, classType] of Object.entries(api))traceAPICoverage(coverage, events, className, classType);const focus = testRunner.hasFocusedTestsOrSuites();(focus ? testRunner.fdescribe : testRunner.describe)(COVERAGE_TESTSUITE_NAME, () => {(focus ? testRunner.fit : testRunner.it)('should call all API methods', () => {const missingMethods = [];+ const extraIgnoredMethods = [];for (const method of coverage.keys()) {- if (!coverage.get(method))+ if (!coverage.get(method) && !ignoredMethods.has(method))missingMethods.push(method);+ else if (coverage.get(method) && ignoredMethods.has(method))+ extraIgnoredMethods.push(method);}+ if (extraIgnoredMethods.length)+ throw new Error('Certain API Methods are called and should not be ignored: ' + extraIgnoredMethods.join(', '));if (missingMethods.length)throw new Error('Certain API Methods are not called: ' + missingMethods.join(', '));});