From a65b0bba5db558ad1bddf80473e35f6339b08122 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 19 Aug 2020 13:30:54 -0700 Subject: [PATCH] test: merge test options into options (#3531) --- test/autowaiting-basic.spec.ts | 3 +- test/base.fixture.ts | 32 ++----- test/browser.spec.ts | 6 +- test/browsercontext-basic.spec.ts | 4 +- test/browsercontext-credentials.spec.ts | 8 +- test/browsertype-basic.spec.ts | 8 +- test/browsertype-connect.spec.ts | 9 +- test/browsertype-launch-server.spec.ts | 21 +++-- test/browsertype-launch.spec.ts | 7 +- test/chromium/launcher.spec.ts | 7 +- test/click-timeout-1.spec.ts | 3 +- test/click-timeout-3.spec.ts | 3 +- test/click.spec.ts | 31 ++++--- test/defaultbrowsercontext.spec.ts | 11 ++- test/download.spec.ts | 3 +- test/elementhandle-bounding-box.spec.ts | 3 +- test/elementhandle-screenshot.spec.ts | 9 +- test/elementhandle-select-text.spec.ts | 8 +- test/emulation-focus.spec.ts | 3 +- test/fixtures.spec.ts | 17 ++-- test/frame-evaluate.spec.ts | 17 ++-- test/keyboard.spec.ts | 8 +- test/mouse.spec.ts | 8 +- test/multiclient.spec.ts | 9 +- test/network-request.spec.ts | 8 +- test/page-basic.spec.ts | 12 +-- test/page-evaluate.spec.ts | 3 +- test/page-event-crash.spec.ts | 3 +- test/page-event-network.spec.ts | 6 +- test/page-event-pageerror.spec.ts | 4 +- test/page-goto.spec.ts | 24 ++--- test/page-route.spec.ts | 12 +-- test/page-screenshot.spec.ts | 3 +- test/pdf.spec.ts | 3 +- test/permissions.spec.ts | 5 +- test/popup.spec.ts | 4 +- test/proxy.spec.ts | 3 +- test/request-fulfill.spec.ts | 5 +- test/runner/fixtures.js | 7 +- test/runner/fixturesUI.js | 1 - test/runner/testCollector.js | 2 - test/runner/testOptions.js | 24 ----- test/runner/testRunner.js | 1 - test/screencast.spec.ts | 7 +- test/slowmo.spec.ts | 112 ++++++++++++------------ test/types.d.ts | 6 -- 46 files changed, 210 insertions(+), 283 deletions(-) delete mode 100644 test/runner/testOptions.js diff --git a/test/autowaiting-basic.spec.ts b/test/autowaiting-basic.spec.ts index 5a9cb7619fa86..a96c2ba321e3d 100644 --- a/test/autowaiting-basic.spec.ts +++ b/test/autowaiting-basic.spec.ts @@ -15,7 +15,6 @@ * limitations under the License. */ import './base.fixture'; -const { WIRE } = testOptions; it('should await navigation when clicking anchor', async({page, server}) => { const messages = []; @@ -201,7 +200,7 @@ it('should work with goto following click', async({page, server}) => { await page.goto(server.EMPTY_PAGE); }); -it.skip(WIRE)('should report navigation in the log when clicking anchor', async({page, server}) => { +it.skip(options.WIRE)('should report navigation in the log when clicking anchor', async({page, server}) => { await page.setContent(`click me`); const __testHookAfterPointerAction = () => new Promise(f => setTimeout(f, 6000)); const error = await page.click('a', { timeout: 5000, __testHookAfterPointerAction } as any).catch(e => e); diff --git a/test/base.fixture.ts b/test/base.fixture.ts index d2f592b3d7557..f6c3f31a006f2 100644 --- a/test/base.fixture.ts +++ b/test/base.fixture.ts @@ -25,7 +25,7 @@ import { Transport } from '../lib/rpc/transport'; import { setUnderTest } from '../lib/helper'; import { installCoverageHooks } from './runner/coverage'; import { valueFromEnv } from './runner/utils'; -import { registerFixture, registerWorkerFixture, registerOption } from './runner/fixtures'; +import { registerFixture, registerWorkerFixture, registerOption, registerOptionGenerator } from './runner/fixtures'; import './runner/builtin.fixtures'; import {mkdtempAsync, removeFolderAsync} from './utils'; @@ -43,9 +43,6 @@ declare global { browserType: BrowserType; browserName: string; browser: Browser; - isChromium: boolean; - isFirefox: boolean; - isWebKit: boolean; } interface FixtureState { toImpl: (rpcObject: any) => any; @@ -60,6 +57,8 @@ declare global { CHROMIUM: boolean; FFOX: boolean; WEBKIT: boolean; + HEADLESS: boolean; + WIRE: boolean; } } @@ -104,14 +103,14 @@ registerWorkerFixture('defaultBrowserOptions', async({browserName}, test) => { await test({ handleSIGINT: false, slowMo: valueFromEnv('SLOW_MO', 0), - headless: !!valueFromEnv('HEADLESS', true), + headless: options.HEADLESS, executablePath }); }); registerWorkerFixture('playwright', async({parallelIndex, browserName}, test) => { const {coverage, uninstall} = installCoverageHooks(browserName); - if (process.env.PWWIRE) { + if (options.WIRE) { const connection = new Connection(); const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'rpc', 'server'), [], { stdio: 'pipe', @@ -185,22 +184,6 @@ registerFixture('server', async ({httpService}, test) => { await test(httpService.server); }); -registerWorkerFixture('browserName', async ({}, test) => { - await test(options.browserName); -}); - -registerWorkerFixture('isChromium', async ({}, test) => { - await test(options.browserName === 'chromium'); -}); - -registerWorkerFixture('isFirefox', async ({}, test) => { - await test(options.browserName === 'firefox'); -}); - -registerWorkerFixture('isWebKit', async ({}, test) => { - await test(options.browserName === 'webkit'); -}); - registerFixture('httpsServer', async ({httpService}, test) => { httpService.httpsServer.reset(); await test(httpService.httpsServer); @@ -220,11 +203,14 @@ registerWorkerFixture('golden', async ({browserName}, test) => { await test(p => path.join(browserName, p)); }); -registerOption('browserName', () => { +registerOptionGenerator('browserName', () => { if (process.env.BROWSER) return [process.env.BROWSER]; return ['chromium', 'webkit', 'firefox']; }); + registerOption('CHROMIUM', ({browserName}) => browserName === 'chromium'); registerOption('FFOX', ({browserName}) => browserName === 'firefox'); registerOption('WEBKIT', ({browserName}) => browserName === 'webkit'); +registerOption('HEADLESS', ({}) => !!valueFromEnv('HEADLESS', true)); +registerOption('WIRE', ({}) => process.env.PWWIRE); diff --git a/test/browser.spec.ts b/test/browser.spec.ts index 56b03c2e57dc9..173bff416f327 100644 --- a/test/browser.spec.ts +++ b/test/browser.spec.ts @@ -15,8 +15,6 @@ */ import './base.fixture'; -import utils from './utils'; - it('should create new page', async function({browser}) { const page1 = await browser.newPage(); expect(browser.contexts().length).toBe(1); @@ -39,9 +37,9 @@ it('should throw upon second create new page', async function({browser}) { expect(error.message).toContain('Please use browser.newContext()'); }); -it('version should work', async function({browser, isChromium}) { +it('version should work', async function({browser}) { const version = browser.version(); - if (isChromium) + if (options.CHROMIUM) expect(version.match(/^\d+\.\d+\.\d+\.\d+$/)).toBeTruthy(); else expect(version.match(/^\d+\.\d+/)).toBeTruthy(); diff --git a/test/browsercontext-basic.spec.ts b/test/browsercontext-basic.spec.ts index 4213023aa2066..700f08f0935f6 100644 --- a/test/browsercontext-basic.spec.ts +++ b/test/browsercontext-basic.spec.ts @@ -177,14 +177,14 @@ it('should close all belonging pages once closing context', async function({brow expect(context.pages().length).toBe(0); }); -it('should disable javascript', async({browser, isWebKit}) => { +it('should disable javascript', async({browser}) => { { const context = await browser.newContext({ javaScriptEnabled: false }); const page = await context.newPage(); await page.goto('data:text/html, '); let error = null; await page.evaluate('something').catch(e => error = e); - if (isWebKit) + if (options.WEBKIT) expect(error.message).toContain('Can\'t find variable: something'); else expect(error.message).toContain('something is not defined'); diff --git a/test/browsercontext-credentials.spec.ts b/test/browsercontext-credentials.spec.ts index 95e61221ca8fe..8de0621b39b8d 100644 --- a/test/browsercontext-credentials.spec.ts +++ b/test/browsercontext-credentials.spec.ts @@ -16,9 +16,7 @@ */ import './base.fixture'; -const { HEADLESS } = testOptions; - -it.fail(options.CHROMIUM && !HEADLESS)('should fail without credentials', async({browser, server}) => { +it.fail(options.CHROMIUM && !options.HEADLESS)('should fail without credentials', async({browser, server}) => { server.setAuth('/empty.html', 'user', 'pass'); const context = await browser.newContext(); const page = await context.newPage(); @@ -27,7 +25,7 @@ it.fail(options.CHROMIUM && !HEADLESS)('should fail without credentials', async( await context.close(); }); -it.fail(options.CHROMIUM && !HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => { +it.fail(options.CHROMIUM && !options.HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => { server.setAuth('/empty.html', 'user', 'pass'); const context = await browser.newContext(); const page = await context.newPage(); @@ -50,7 +48,7 @@ it('should work with correct credentials', async({browser, server}) => { await context.close(); }); -it.fail(options.CHROMIUM && !HEADLESS)('should fail with wrong credentials', async({browser, server}) => { +it.fail(options.CHROMIUM && !options.HEADLESS)('should fail with wrong credentials', async({browser, server}) => { server.setAuth('/empty.html', 'user', 'pass'); const context = await browser.newContext({ httpCredentials: { username: 'foo', password: 'bar' } diff --git a/test/browsertype-basic.spec.ts b/test/browsertype-basic.spec.ts index a0075f7f87863..e2f3ac916a019 100644 --- a/test/browsertype-basic.spec.ts +++ b/test/browsertype-basic.spec.ts @@ -24,12 +24,12 @@ it('browserType.executablePath should work', async({browserType}) => { expect(fs.realpathSync(executablePath)).toBe(executablePath); }); -it('browserType.name should work', async({browserType, isWebKit, isFirefox, isChromium}) => { - if (isWebKit) +it('browserType.name should work', async({browserType}) => { + if (options.WEBKIT) expect(browserType.name()).toBe('webkit'); - else if (isFirefox) + else if (options.FFOX) expect(browserType.name()).toBe('firefox'); - else if (isChromium) + else if (options.CHROMIUM) expect(browserType.name()).toBe('chromium'); else throw new Error('Unknown browser'); diff --git a/test/browsertype-connect.spec.ts b/test/browsertype-connect.spec.ts index 41e3208067075..33049257f58e7 100644 --- a/test/browsertype-connect.spec.ts +++ b/test/browsertype-connect.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -it.skip(WIRE).slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => { +it.skip(options.WIRE).slow()('should be able to reconnect to a browser', async({browserType, defaultBrowserOptions, server}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); { const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); @@ -37,7 +36,7 @@ it.skip(WIRE).slow()('should be able to reconnect to a browser', async({browserT await browserServer.close(); }); -it.skip(WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') }; const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e); @@ -45,7 +44,7 @@ it.skip(WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions dur expect(error.message).toContain('Dummy'); }); -it.skip(WIRE)('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should set the browser connected state', async ({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); expect(remote.isConnected()).toBe(true); @@ -54,7 +53,7 @@ it.skip(WIRE)('should set the browser connected state', async ({browserType, def await browserServer.close(); }); -it.skip(WIRE)('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should throw when used after isConnected returns false', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const page = await remote.newPage(); diff --git a/test/browsertype-launch-server.spec.ts b/test/browsertype-launch-server.spec.ts index 9758de565b296..92cc3f44ff0ce 100644 --- a/test/browsertype-launch-server.spec.ts +++ b/test/browsertype-launch-server.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -it.skip(WIRE)('should work', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should work', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browserContext = await browser.newContext(); @@ -31,7 +30,7 @@ it.skip(WIRE)('should work', async({browserType, defaultBrowserOptions}) => { await browserServer.close(); }); -it.skip(WIRE)('should fire "disconnected" when closing the server', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should fire "disconnected" when closing the server', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const browser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve)); @@ -43,7 +42,7 @@ it.skip(WIRE)('should fire "disconnected" when closing the server', async({brows ]); }); -it.skip(WIRE)('should fire "close" event during kill', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should fire "close" event during kill', async({browserType, defaultBrowserOptions}) => { const order = []; const browserServer = await browserType.launchServer(defaultBrowserOptions); const closedPromise = new Promise(f => browserServer.on('close', () => { @@ -57,13 +56,13 @@ it.skip(WIRE)('should fire "close" event during kill', async({browserType, defau expect(order).toEqual(['closed', 'killed']); }); -it.skip(WIRE)('should return child_process instance', async ({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should return child_process instance', async ({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); expect(browserServer.process().pid).toBeGreaterThan(0); await browserServer.close(); }); -it.skip(WIRE)('should fire close event', async ({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should fire close event', async ({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const [result] = await Promise.all([ new Promise(f => (browserServer as any).on('close', (exitCode, signal) => f({ exitCode, signal }))), @@ -73,7 +72,7 @@ it.skip(WIRE)('should fire close event', async ({browserType, defaultBrowserOpti expect(result['signal']).toBe(null); }); -it.skip(WIRE)('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => { +it.skip(options.WIRE)('should reject navigation when browser closes', async({browserType, defaultBrowserOptions, server}) => { server.setRoute('/one-style.css', () => {}); const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); @@ -86,7 +85,7 @@ it.skip(WIRE)('should reject navigation when browser closes', async({browserType await browserServer.close(); }); -it.skip(WIRE)('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => { +it.skip(options.WIRE)('should reject waitForSelector when browser closes', async({browserType, defaultBrowserOptions, server}) => { server.setRoute('/empty.html', () => {}); const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); @@ -102,7 +101,7 @@ it.skip(WIRE)('should reject waitForSelector when browser closes', async({browse await browserServer.close(); }); -it.skip(WIRE)('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should throw if used after disconnect', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const page = await remote.newPage(); @@ -112,7 +111,7 @@ it.skip(WIRE)('should throw if used after disconnect', async({browserType, defau await browserServer.close(); }); -it.skip(WIRE)('should emit close events on pages and contexts', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should emit close events on pages and contexts', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const context = await remote.newContext(); @@ -126,7 +125,7 @@ it.skip(WIRE)('should emit close events on pages and contexts', async({browserTy expect(pageClosed).toBeTruthy(); }); -it.skip(WIRE)('should terminate network waiters', async({browserType, defaultBrowserOptions, server}) => { +it.skip(options.WIRE)('should terminate network waiters', async({browserType, defaultBrowserOptions, server}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const newPage = await remote.newPage(); diff --git a/test/browsertype-launch.spec.ts b/test/browsertype-launch.spec.ts index 97449a2a0a84a..0c27db9a83053 100644 --- a/test/browsertype-launch.spec.ts +++ b/test/browsertype-launch.spec.ts @@ -18,7 +18,6 @@ import path from 'path'; import './base.fixture'; -const { WIRE } = testOptions; it('should reject all promises when browser is closed', async({browserType, defaultBrowserOptions}) => { const browser = await browserType.launch(defaultBrowserOptions); @@ -60,7 +59,7 @@ it('should reject if executable path is invalid', async({browserType, defaultBro expect(waitError.message).toContain('Failed to launch'); }); -it.skip(WIRE)('should handle timeout', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should handle timeout', async({browserType, defaultBrowserOptions}) => { const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) }; const error = await browserType.launch(options).catch(e => e); expect(error.message).toContain(`browserType.launch: Timeout 5000ms exceeded.`); @@ -68,14 +67,14 @@ it.skip(WIRE)('should handle timeout', async({browserType, defaultBrowserOptions expect(error.message).toContain(` pid=`); }); -it.skip(WIRE)('should handle exception', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should handle exception', async({browserType, defaultBrowserOptions}) => { const e = new Error('Dummy'); const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 }; const error = await browserType.launch(options).catch(e => e); expect(error.message).toContain('Dummy'); }); -it.skip(WIRE)('should report launch log', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should report launch log', async({browserType, defaultBrowserOptions}) => { const e = new Error('Dummy'); const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; }, timeout: 9000 }; const error = await browserType.launch(options).catch(e => e); diff --git a/test/chromium/launcher.spec.ts b/test/chromium/launcher.spec.ts index b91622893f9a5..2758eca624742 100644 --- a/test/chromium/launcher.spec.ts +++ b/test/chromium/launcher.spec.ts @@ -19,23 +19,22 @@ import path from 'path'; import utils from '../utils'; import { ChromiumBrowser, ChromiumBrowserContext } from '../..'; const { makeUserDataDir, removeUserDataDir } = utils; -const { WIRE } = testOptions; -it.skip(WIRE || !options.CHROMIUM)('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE || !options.CHROMIUM)('should throw with remote-debugging-pipe argument', async({browserType, defaultBrowserOptions}) => { const options = Object.assign({}, defaultBrowserOptions); options.args = ['--remote-debugging-pipe'].concat(options.args || []); const error = await browserType.launchServer(options).catch(e => e); expect(error.message).toContain('Playwright manages remote debugging connection itself'); }); -it.skip(WIRE || !options.CHROMIUM)('should not throw with remote-debugging-port argument', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE || !options.CHROMIUM)('should not throw with remote-debugging-port argument', async({browserType, defaultBrowserOptions}) => { const options = Object.assign({}, defaultBrowserOptions); options.args = ['--remote-debugging-port=0'].concat(options.args || []); const browser = await browserType.launchServer(options); await browser.close(); }); -it.skip(!options.CHROMIUM || WIRE || WIN)('should open devtools when "devtools: true" option is given', async({browserType, defaultBrowserOptions}) => { +it.skip(!options.CHROMIUM || options.WIRE || WIN)('should open devtools when "devtools: true" option is given', async({browserType, defaultBrowserOptions}) => { let devtoolsCallback; const devtoolsPromise = new Promise(f => devtoolsCallback = f); const __testHookForDevTools = devtools => devtools.__testHookOnBinding = parsed => { diff --git a/test/click-timeout-1.spec.ts b/test/click-timeout-1.spec.ts index 1a6ed6ee9ce36..b378f5fb588f4 100644 --- a/test/click-timeout-1.spec.ts +++ b/test/click-timeout-1.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -it.skip(WIRE)('should avoid side effects after timeout', async({page, server}) => { +it.skip(options.WIRE)('should avoid side effects after timeout', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); const error = await page.click('button', { timeout: 2000, __testHookBeforePointerAction: () => new Promise(f => setTimeout(f, 2500))} as any).catch(e => e); await page.waitForTimeout(5000); // Give it some time to click after the test hook is done waiting. diff --git a/test/click-timeout-3.spec.ts b/test/click-timeout-3.spec.ts index 8b77a4a9dd58e..73792e2bcebb5 100644 --- a/test/click-timeout-3.spec.ts +++ b/test/click-timeout-3.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -it.skip(WIRE)('should fail when element jumps during hit testing', async({page, server}) => { +it.skip(options.WIRE)('should fail when element jumps during hit testing', async({page, server}) => { await page.setContent(''); let clicked = false; const handle = await page.$('button'); diff --git a/test/click.spec.ts b/test/click.spec.ts index f7412a046086c..afabc30f058b5 100644 --- a/test/click.spec.ts +++ b/test/click.spec.ts @@ -17,7 +17,6 @@ import './base.fixture'; import utils from './utils'; -const { HEADLESS } = testOptions; async function giveItAChanceToClick(page) { for (let i = 0; i < 5; i++) @@ -344,39 +343,39 @@ it('should click the button with deviceScaleFactor set', async({browser, server} await context.close(); }); -it('should click the button with px border with offset', async({page, server, isWebKit}) => { +it('should click the button with px border with offset', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.$eval('button', button => button.style.borderWidth = '8px'); await page.click('button', { position: { x: 20, y: 10 } }); expect(await page.evaluate('result')).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate('offsetX')).toBe(isWebKit ? 20 + 8 : 20); - expect(await page.evaluate('offsetY')).toBe(isWebKit ? 10 + 8 : 10); + expect(await page.evaluate('offsetX')).toBe(options.WEBKIT ? 20 + 8 : 20); + expect(await page.evaluate('offsetY')).toBe(options.WEBKIT ? 10 + 8 : 10); }); -it('should click the button with em border with offset', async({page, server, isWebKit}) => { +it('should click the button with em border with offset', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.$eval('button', button => button.style.borderWidth = '2em'); await page.$eval('button', button => button.style.fontSize = '12px'); await page.click('button', { position: { x: 20, y: 10 } }); expect(await page.evaluate('result')).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate('offsetX')).toBe(isWebKit ? 12 * 2 + 20 : 20); - expect(await page.evaluate('offsetY')).toBe(isWebKit ? 12 * 2 + 10 : 10); + expect(await page.evaluate('offsetX')).toBe(options.WEBKIT ? 12 * 2 + 20 : 20); + expect(await page.evaluate('offsetY')).toBe(options.WEBKIT ? 12 * 2 + 10 : 10); }); -it('should click a very large button with offset', async({page, server, isWebKit}) => { +it('should click a very large button with offset', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.$eval('button', button => button.style.borderWidth = '8px'); await page.$eval('button', button => button.style.height = button.style.width = '2000px'); await page.click('button', { position: { x: 1900, y: 1910 } }); expect(await page.evaluate(() => window['result'])).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate('offsetX')).toBe(isWebKit ? 1900 + 8 : 1900); - expect(await page.evaluate('offsetY')).toBe(isWebKit ? 1910 + 8 : 1910); + expect(await page.evaluate('offsetX')).toBe(options.WEBKIT ? 1900 + 8 : 1900); + expect(await page.evaluate('offsetY')).toBe(options.WEBKIT ? 1910 + 8 : 1910); }); -it('should click a button in scrolling container with offset', async({page, server, isWebKit}) => { +it('should click a button in scrolling container with offset', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.$eval('button', button => { const container = document.createElement('div'); @@ -392,11 +391,11 @@ it('should click a button in scrolling container with offset', async({page, serv await page.click('button', { position: { x: 1900, y: 1910 } }); expect(await page.evaluate(() => window['result'])).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate('offsetX')).toBe(isWebKit ? 1900 + 8 : 1900); - expect(await page.evaluate('offsetY')).toBe(isWebKit ? 1910 + 8 : 1910); + expect(await page.evaluate('offsetX')).toBe(options.WEBKIT ? 1900 + 8 : 1900); + expect(await page.evaluate('offsetY')).toBe(options.WEBKIT ? 1910 + 8 : 1910); }); -it.skip(options.FFOX)('should click the button with offset with page scale', async({browser, server, isChromium, isWebKit}) => { +it.skip(options.FFOX)('should click the button with offset with page scale', async({browser, server}) => { const context = await browser.newContext({ viewport: { width: 400, height: 400 }, isMobile: true }); const page = await context.newPage(); await page.goto(server.PREFIX + '/input/button.html'); @@ -408,10 +407,10 @@ it.skip(options.FFOX)('should click the button with offset with page scale', asy expect(await page.evaluate('result')).toBe('Clicked'); const round = x => Math.round(x + 0.01); let expected = { x: 28, y: 18 }; // 20;10 + 8px of border in each direction - if (isWebKit) { + if (options.WEBKIT) { // WebKit rounds up during css -> dip -> css conversion. expected = { x: 29, y: 19 }; - } else if (isChromium && HEADLESS) { + } else if (options.CHROMIUM && options.HEADLESS) { // Headless Chromium rounds down during css -> dip -> css conversion. expected = { x: 27, y: 18 }; } diff --git a/test/defaultbrowsercontext.spec.ts b/test/defaultbrowsercontext.spec.ts index e5abbeefa030b..597d5f32ca655 100644 --- a/test/defaultbrowsercontext.spec.ts +++ b/test/defaultbrowsercontext.spec.ts @@ -22,7 +22,6 @@ import fs from 'fs'; import utils from './utils'; import { BrowserType, Browser, BrowserContext, Page } from '..'; const { removeUserDataDir, makeUserDataDir } = utils; -const { WIRE } = testOptions; declare global { interface FixtureState { @@ -171,12 +170,12 @@ it('should support bypassCSP option', async ({server, launchPersistent}) => { expect(await page.evaluate('__injected')).toBe(42); }); -it('should support javascriptEnabled option', async ({launchPersistent, isWebKit}) => { +it('should support javascriptEnabled option', async ({launchPersistent}) => { const {page, context} = await launchPersistent({javaScriptEnabled: false}); await page.goto('data:text/html, '); let error = null; await page.evaluate('something').catch(e => error = e); - if (isWebKit) + if (options.WEBKIT) expect(error.message).toContain('Can\'t find variable: something'); else expect(error.message).toContain('something is not defined'); @@ -346,7 +345,7 @@ it.skip(options.FFOX)('should throw if page argument is passed', async ({browser expect(error.message).toContain('can not specify page'); }); -it.skip(WIRE)('should have passed URL when launching with ignoreDefaultArgs: true', async ({browserType, defaultBrowserOptions, server, tmpDir, toImpl}) => { +it.skip(options.WIRE)('should have passed URL when launching with ignoreDefaultArgs: true', async ({browserType, defaultBrowserOptions, server, tmpDir, toImpl}) => { const args = toImpl(browserType)._defaultArgs(defaultBrowserOptions, 'persistent', tmpDir, 0).filter(a => a !== 'about:blank'); const options = { ...defaultBrowserOptions, @@ -362,13 +361,13 @@ it.skip(WIRE)('should have passed URL when launching with ignoreDefaultArgs: tru await browserContext.close(); }); -it.skip(WIRE)('should handle timeout', async({browserType, defaultBrowserOptions, tmpDir}) => { +it.skip(options.WIRE)('should handle timeout', async({browserType, defaultBrowserOptions, tmpDir}) => { const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) }; const error = await browserType.launchPersistentContext(tmpDir, options).catch(e => e); expect(error.message).toContain(`browserType.launchPersistentContext: Timeout 5000ms exceeded.`); }); -it.skip(WIRE)('should handle exception', async({browserType, defaultBrowserOptions, tmpDir}) => { +it.skip(options.WIRE)('should handle exception', async({browserType, defaultBrowserOptions, tmpDir}) => { const e = new Error('Dummy'); const options = { ...defaultBrowserOptions, __testHookBeforeCreateBrowser: () => { throw e; } }; const error = await browserType.launchPersistentContext(tmpDir, options).catch(e => e); diff --git a/test/download.spec.ts b/test/download.spec.ts index 3772ad6417f38..86b79c3fc3e1c 100644 --- a/test/download.spec.ts +++ b/test/download.spec.ts @@ -21,7 +21,6 @@ import fs from 'fs'; import path from 'path'; import util from 'util'; -const { HEADLESS } = testOptions; beforeEach(async ({server}) => { server.setRoute('/download', (req, res) => { @@ -240,7 +239,7 @@ it.fail(options.FFOX || options.WEBKIT)('should report alt-click downloads', asy await page.close(); }); -it.fail(options.CHROMIUM && !HEADLESS)('should report new window downloads', async({browser, server}) => { +it.fail(options.CHROMIUM && !options.HEADLESS)('should report new window downloads', async({browser, server}) => { // TODO: - the test fails in headful Chromium as the popup page gets closed along // with the session before download completed event arrives. // - WebKit doesn't close the popup page diff --git a/test/elementhandle-bounding-box.spec.ts b/test/elementhandle-bounding-box.spec.ts index 6cb36ab132986..53960f450dccf 100644 --- a/test/elementhandle-bounding-box.spec.ts +++ b/test/elementhandle-bounding-box.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { HEADLESS } = testOptions; -it.fail(options.FFOX && !HEADLESS)('should work', async ({ page, server }) => { +it.fail(options.FFOX && !options.HEADLESS)('should work', async ({ page, server }) => { await page.setViewportSize({ width: 500, height: 500 }); await page.goto(server.PREFIX + '/grid.html'); const elementHandle = await page.$('.box:nth-of-type(13)'); diff --git a/test/elementhandle-screenshot.spec.ts b/test/elementhandle-screenshot.spec.ts index 8dd4a7afd8191..9dfb7354bcdd7 100644 --- a/test/elementhandle-screenshot.spec.ts +++ b/test/elementhandle-screenshot.spec.ts @@ -17,13 +17,12 @@ import './base.fixture'; import utils from './utils'; -const {WIRE, HEADLESS} = testOptions; import {PNG} from 'pngjs'; import path from 'path'; import fs from 'fs'; // Firefox headful produces a different image. -const ffheadful = options.FFOX && !HEADLESS; +const ffheadful = options.FFOX && !options.HEADLESS; it.skip(ffheadful)('should work', async({page, server, golden}) => { await page.setViewportSize({width: 500, height: 500}); @@ -285,7 +284,7 @@ it.skip(ffheadful)('should restore default viewport after fullPage screenshot', await context.close(); }); -it.skip(ffheadful || WIRE)('should restore viewport after page screenshot and exception', async({ browser, server }) => { +it.skip(ffheadful || options.WIRE)('should restore viewport after page screenshot and exception', async({ browser, server }) => { const context = await browser.newContext({ viewport: { width: 350, height: 360 } }); const page = await context.newPage(); await page.goto(server.PREFIX + '/grid.html'); @@ -296,7 +295,7 @@ it.skip(ffheadful || WIRE)('should restore viewport after page screenshot and ex await context.close(); }); -it.skip(ffheadful || WIRE)('should restore viewport after page screenshot and timeout', async({ browser, server }) => { +it.skip(ffheadful || options.WIRE)('should restore viewport after page screenshot and timeout', async({ browser, server }) => { const context = await browser.newContext({ viewport: { width: 350, height: 360 } }); const page = await context.newPage(); await page.goto(server.PREFIX + '/grid.html'); @@ -340,7 +339,7 @@ it.skip(ffheadful)('should take element screenshot when default viewport is null await context.close(); }); -it.skip(ffheadful || WIRE)('should restore viewport after element screenshot and exception', async({server, browser}) => { +it.skip(ffheadful || options.WIRE)('should restore viewport after element screenshot and exception', async({server, browser}) => { const context = await browser.newContext({ viewport: { width: 350, height: 360 } }); const page = await context.newPage(); await page.setContent(`
`); diff --git a/test/elementhandle-select-text.spec.ts b/test/elementhandle-select-text.spec.ts index 6829694056e78..9047eb7d541d2 100644 --- a/test/elementhandle-select-text.spec.ts +++ b/test/elementhandle-select-text.spec.ts @@ -16,12 +16,12 @@ */ import './base.fixture'; -it('should select textarea', async ({ page, server, isFirefox }) => { +it('should select textarea', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/textarea.html'); const textarea = await page.$('textarea'); await textarea.evaluate(textarea => textarea.value = 'some value'); await textarea.selectText(); - if (isFirefox) { + if (options.FFOX) { expect(await textarea.evaluate(el => el.selectionStart)).toBe(0); expect(await textarea.evaluate(el => el.selectionEnd)).toBe(10); } else { @@ -29,12 +29,12 @@ it('should select textarea', async ({ page, server, isFirefox }) => { } }); -it('should select input', async ({ page, server, isFirefox }) => { +it('should select input', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/textarea.html'); const input = await page.$('input'); await input.evaluate(input => input.value = 'some value'); await input.selectText(); - if (isFirefox) { + if (options.FFOX) { expect(await input.evaluate(el => el.selectionStart)).toBe(0); expect(await input.evaluate(el => el.selectionEnd)).toBe(10); } else { diff --git a/test/emulation-focus.spec.ts b/test/emulation-focus.spec.ts index 5f8d6d3d4174e..f8d323ead0bbf 100644 --- a/test/emulation-focus.spec.ts +++ b/test/emulation-focus.spec.ts @@ -18,7 +18,6 @@ import './base.fixture'; import utils from './utils'; -const { HEADLESS } = testOptions; it('should think that it is focused by default', async({page}) => { expect(await page.evaluate('document.hasFocus()')).toBe(true); @@ -103,7 +102,7 @@ it('should change document.activeElement', async({page, server}) => { expect(active).toEqual(['INPUT', 'TEXTAREA']); }); -it.skip(options.FFOX && !HEADLESS)('should not affect screenshots', async({page, server, golden}) => { +it.skip(options.FFOX && !options.HEADLESS)('should not affect screenshots', async({page, server, golden}) => { // Firefox headful produces a different image. const page2 = await page.context().newPage(); await Promise.all([ diff --git a/test/fixtures.spec.ts b/test/fixtures.spec.ts index a2bc98e582200..5d642f58a6971 100644 --- a/test/fixtures.spec.ts +++ b/test/fixtures.spec.ts @@ -20,7 +20,6 @@ import { registerFixture } from './runner/fixtures'; import path from 'path'; import {spawn, execSync} from 'child_process'; import { BrowserType, Browser, LaunchOptions } from '..'; -const { HEADLESS } = testOptions; const playwrightPath = path.join(__dirname, '..'); @@ -129,7 +128,7 @@ it.slow()('should close the browser when the node process closes', async ({wrapp }); // Cannot reliably send signals on Windows. -it.skip(WIN || !HEADLESS).slow()('should report browser close signal', async ({wrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should report browser close signal', async ({wrapper}) => { const pid = await wrapper.out('pid'); process.kill(-pid, 'SIGTERM'); expect(await wrapper.out('exitCode')).toBe('null'); @@ -138,7 +137,7 @@ it.skip(WIN || !HEADLESS).slow()('should report browser close signal', async ({w await wrapper.childExitCode(); }); -it.skip(WIN || !HEADLESS).slow()('should report browser close signal 2', async ({wrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should report browser close signal 2', async ({wrapper}) => { const pid = await wrapper.out('pid'); process.kill(-pid, 'SIGKILL'); expect(await wrapper.out('exitCode')).toBe('null'); @@ -147,28 +146,28 @@ it.skip(WIN || !HEADLESS).slow()('should report browser close signal 2', async ( await wrapper.childExitCode(); }); -it.skip(WIN || !HEADLESS).slow()('should close the browser on SIGINT', async ({wrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should close the browser on SIGINT', async ({wrapper}) => { process.kill(wrapper.child().pid, 'SIGINT'); expect(await wrapper.out('exitCode')).toBe('0'); expect(await wrapper.out('signal')).toBe('null'); expect(await wrapper.childExitCode()).toBe(130); }); -it.skip(WIN || !HEADLESS).slow()('should close the browser on SIGTERM', async ({wrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should close the browser on SIGTERM', async ({wrapper}) => { process.kill(wrapper.child().pid, 'SIGTERM'); expect(await wrapper.out('exitCode')).toBe('0'); expect(await wrapper.out('signal')).toBe('null'); expect(await wrapper.childExitCode()).toBe(0); }); -it.skip(WIN || !HEADLESS).slow()('should close the browser on SIGHUP', async ({wrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should close the browser on SIGHUP', async ({wrapper}) => { process.kill(wrapper.child().pid, 'SIGHUP'); expect(await wrapper.out('exitCode')).toBe('0'); expect(await wrapper.out('signal')).toBe('null'); expect(await wrapper.childExitCode()).toBe(0); }); -it.skip(WIN || !HEADLESS).slow()('should kill the browser on double SIGINT', async ({stallingWrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should kill the browser on double SIGINT', async ({stallingWrapper}) => { const wrapper = stallingWrapper; process.kill(wrapper.child().pid, 'SIGINT'); await wrapper.out('stalled'); @@ -178,7 +177,7 @@ it.skip(WIN || !HEADLESS).slow()('should kill the browser on double SIGINT', asy expect(await wrapper.childExitCode()).toBe(130); }); -it.skip(WIN || !HEADLESS).slow()('should kill the browser on SIGINT + SIGTERM', async ({stallingWrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should kill the browser on SIGINT + SIGTERM', async ({stallingWrapper}) => { const wrapper = stallingWrapper; process.kill(wrapper.child().pid, 'SIGINT'); await wrapper.out('stalled'); @@ -188,7 +187,7 @@ it.skip(WIN || !HEADLESS).slow()('should kill the browser on SIGINT + SIGTERM', expect(await wrapper.childExitCode()).toBe(0); }); -it.skip(WIN || !HEADLESS).slow()('should kill the browser on SIGTERM + SIGINT', async ({stallingWrapper}) => { +it.skip(WIN || !options.HEADLESS).slow()('should kill the browser on SIGTERM + SIGINT', async ({stallingWrapper}) => { const wrapper = stallingWrapper; process.kill(wrapper.child().pid, 'SIGTERM'); await wrapper.out('stalled'); diff --git a/test/frame-evaluate.spec.ts b/test/frame-evaluate.spec.ts index bf109bbd2b92e..bba366f4c5b70 100644 --- a/test/frame-evaluate.spec.ts +++ b/test/frame-evaluate.spec.ts @@ -17,7 +17,6 @@ import './base.fixture'; import utils from './utils'; -const { WIRE } = testOptions; it('should have different execution contexts', async ({ page, server }) => { await page.goto(server.EMPTY_PAGE); @@ -36,27 +35,27 @@ it('should have correct execution contexts', async ({ page, server }) => { expect(await page.frames()[1].evaluate(() => document.body.textContent.trim())).toBe(`Hi, I'm frame`); }); -function expectContexts(pageImpl, count, isChromium) { - if (isChromium) +function expectContexts(pageImpl, count) { + if (options.CHROMIUM) expect(pageImpl._delegate._mainFrameSession._contextIdToContext.size).toBe(count); else expect(pageImpl._delegate._contextIdToContext.size).toBe(count); } -it.skip(WIRE)('should dispose context on navigation', async ({ page, server, toImpl, isChromium }) => { +it.skip(options.WIRE)('should dispose context on navigation', async ({ page, server, toImpl }) => { await page.goto(server.PREFIX + '/frames/one-frame.html'); expect(page.frames().length).toBe(2); - expectContexts(toImpl(page), 4, isChromium); + expectContexts(toImpl(page), 4); await page.goto(server.EMPTY_PAGE); - expectContexts(toImpl(page), 2, isChromium); + expectContexts(toImpl(page), 2); }); -it.skip(WIRE)('should dispose context on cross-origin navigation', async ({ page, server, toImpl, isChromium }) => { +it.skip(options.WIRE)('should dispose context on cross-origin navigation', async ({ page, server, toImpl }) => { await page.goto(server.PREFIX + '/frames/one-frame.html'); expect(page.frames().length).toBe(2); - expectContexts(toImpl(page), 4, isChromium); + expectContexts(toImpl(page), 4); await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html'); - expectContexts(toImpl(page), 2, isChromium); + expectContexts(toImpl(page), 2); }); it('should execute after cross-site navigation', async ({ page, server }) => { diff --git a/test/keyboard.spec.ts b/test/keyboard.spec.ts index 2fa00d2784788..4e639161976bd 100644 --- a/test/keyboard.spec.ts +++ b/test/keyboard.spec.ts @@ -350,21 +350,21 @@ it.skip(!MAC)('should support MacOS shortcuts', async ({page, server}) => { expect(await page.$eval('textarea', textarea => textarea.value)).toBe('some '); }); -it('should press the meta key', async ({page, isFirefox}) => { +it('should press the meta key', async ({page}) => { const lastEvent = await captureLastKeydown(page); await page.keyboard.press('Meta'); const {key, code, metaKey} = await lastEvent.jsonValue(); - if (isFirefox && !MAC) + if (options.FFOX && !MAC) expect(key).toBe('OS'); else expect(key).toBe('Meta'); - if (isFirefox) + if (options.FFOX) expect(code).toBe('OSLeft'); else expect(code).toBe('MetaLeft'); - if (isFirefox && !MAC) + if (options.FFOX && !MAC) expect(metaKey).toBe(false); else expect(metaKey).toBe(true); diff --git a/test/mouse.spec.ts b/test/mouse.spec.ts index 088fe664d3289..47967a83a0283 100644 --- a/test/mouse.spec.ts +++ b/test/mouse.spec.ts @@ -121,12 +121,12 @@ it('should trigger hover state with removed window.Node', async({page, server}) expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6'); }); -it('should set modifier keys on click', async({page, server, isFirefox}) => { +it('should set modifier keys on click', async({page, server}) => { await page.goto(server.PREFIX + '/input/scrollable.html'); await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window["lastEvent"] = e, true)); const modifiers = {'Shift': 'shiftKey', 'Control': 'ctrlKey', 'Alt': 'altKey', 'Meta': 'metaKey'}; // In Firefox, the Meta modifier only exists on Mac - if (isFirefox && !MAC) + if (options.FFOX && !MAC) delete modifiers['Meta']; for (const modifier in modifiers) { await page.keyboard.down(modifier); @@ -142,9 +142,9 @@ it('should set modifier keys on click', async({page, server, isFirefox}) => { } }); -it('should tween mouse movement', async({page, isWebKit}) => { +it('should tween mouse movement', async({page}) => { // The test becomes flaky on WebKit without next line. - if (isWebKit) + if (options.WEBKIT) await page.evaluate(() => new Promise(requestAnimationFrame)); await page.mouse.move(100, 100); await page.evaluate(() => { diff --git a/test/multiclient.spec.ts b/test/multiclient.spec.ts index 24ed22912cd7a..a7fe2ef28f488 100644 --- a/test/multiclient.spec.ts +++ b/test/multiclient.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -it.skip(WIRE)('should work across sessions', async ({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should work across sessions', async ({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); expect(browser1.contexts().length).toBe(0); @@ -38,7 +37,7 @@ it.skip(WIRE)('should work across sessions', async ({browserType, defaultBrowser await browserServer.close(); }); -it.skip(WIRE).slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async ({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE).slow()('should be emitted when: browser gets closed, disconnected or underlying websocket gets closed', async ({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const originalBrowser = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const wsEndpoint = browserServer.wsEndpoint(); @@ -72,7 +71,7 @@ it.skip(WIRE).slow()('should be emitted when: browser gets closed, disconnected expect(disconnectedRemote2).toBe(1); }); -it.skip(WIRE)('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should be able to connect multiple times to the same browser', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); const browser1 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); const browser2 = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); @@ -86,7 +85,7 @@ it.skip(WIRE)('should be able to connect multiple times to the same browser', as await browserServer.close(); }); -it.skip(WIRE)('should not be able to close remote browser', async({browserType, defaultBrowserOptions}) => { +it.skip(options.WIRE)('should not be able to close remote browser', async({browserType, defaultBrowserOptions}) => { const browserServer = await browserType.launchServer(defaultBrowserOptions); { const remote = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint() }); diff --git a/test/network-request.spec.ts b/test/network-request.spec.ts index a4e121134ccdc..63cf5372f9193 100644 --- a/test/network-request.spec.ts +++ b/test/network-request.spec.ts @@ -45,13 +45,13 @@ it('should work for fetch requests', async({page, server}) => { expect(requests[0].frame()).toBe(page.mainFrame()); }); -it('should return headers', async({page, server, isChromium, isFirefox, isWebKit}) => { +it('should return headers', async({page, server}) => { const response = await page.goto(server.EMPTY_PAGE); - if (isChromium) + if (options.CHROMIUM) expect(response.request().headers()['user-agent']).toContain('Chrome'); - else if (isFirefox) + else if (options.FFOX) expect(response.request().headers()['user-agent']).toContain('Firefox'); - else if (isWebKit) + else if (options.WEBKIT) expect(response.request().headers()['user-agent']).toContain('WebKit'); }); diff --git a/test/page-basic.spec.ts b/test/page-basic.spec.ts index a6748a8e63d02..5e37f06351889 100644 --- a/test/page-basic.spec.ts +++ b/test/page-basic.spec.ts @@ -33,7 +33,7 @@ it('should not be visible in context.pages', async({context}) => { expect(context.pages()).not.toContain(newPage); }); -it('should run beforeunload if asked for', async({context, server, isChromium, isWebKit}) => { +it('should run beforeunload if asked for', async({context, server}) => { const newPage = await context.newPage(); await newPage.goto(server.PREFIX + '/beforeunload.html'); // We have to interact with a page so that 'beforeunload' handlers @@ -43,9 +43,9 @@ it('should run beforeunload if asked for', async({context, server, isChromium, i const dialog = await newPage.waitForEvent('dialog'); expect(dialog.type()).toBe('beforeunload'); expect(dialog.defaultValue()).toBe(''); - if (isChromium) + if (options.CHROMIUM) expect(dialog.message()).toBe(''); - else if (isWebKit) + else if (options.WEBKIT) expect(dialog.message()).toBe('Leave?'); else expect(dialog.message()).toBe('This page is asking you to confirm that you want to leave - data you have entered may not be saved.'); @@ -196,7 +196,7 @@ it('page.frame should respect url', async function({page, server}) { expect(page.frame({ url: /empty/ }).url()).toBe(server.EMPTY_PAGE); }); -it('should have sane user agent', async ({page, isChromium, isFirefox}) => { +it('should have sane user agent', async ({page}) => { const userAgent = await page.evaluate(() => navigator.userAgent); const [ part1, @@ -210,7 +210,7 @@ it('should have sane user agent', async ({page, isChromium, isFirefox}) => { // Second part in parenthesis is platform - ignore it. // Third part for Firefox is the last one and encodes engine and browser versions. - if (isFirefox) { + if (options.FFOX) { const [engine, browser] = part3.split(' '); expect(engine.startsWith('Gecko')).toBe(true); expect(browser.startsWith('Firefox')).toBe(true); @@ -224,7 +224,7 @@ it('should have sane user agent', async ({page, isChromium, isFirefox}) => { // 5th part encodes real browser name and engine version. const [engine, browser] = part5.split(' '); expect(browser.startsWith('Safari/')).toBe(true); - if (isChromium) + if (options.CHROMIUM) expect(engine.includes('Chrome/')).toBe(true); else expect(engine.startsWith('Version/')).toBe(true); diff --git a/test/page-evaluate.spec.ts b/test/page-evaluate.spec.ts index ae23d6b946d57..7c0b2040c09f6 100644 --- a/test/page-evaluate.spec.ts +++ b/test/page-evaluate.spec.ts @@ -15,7 +15,6 @@ * limitations under the License. */ import './base.fixture'; -const { WIRE } = testOptions; it('should work', async ({ page, server }) => { const result = await page.evaluate(() => 7 * 3); @@ -433,7 +432,7 @@ it('should not throw an error when evaluation does a synchronous navigation and expect(result).toBe(undefined); }); -it.fail(WIRE)('should transfer 100Mb of data from page to node.js', async ({ page }) => { +it.fail(options.WIRE)('should transfer 100Mb of data from page to node.js', async ({ page }) => { // This is too slow with wire. const a = await page.evaluate(() => Array(100 * 1024 * 1024 + 1).join('a')); expect(a.length).toBe(100 * 1024 * 1024); diff --git a/test/page-event-crash.spec.ts b/test/page-event-crash.spec.ts index 4d55c6c65d1a4..e260847468dc8 100644 --- a/test/page-event-crash.spec.ts +++ b/test/page-event-crash.spec.ts @@ -16,9 +16,8 @@ */ import './base.fixture'; -const { WIRE } = testOptions; -const CRASH_FAIL = (options.FFOX && WIN) || WIRE; +const CRASH_FAIL = (options.FFOX && WIN) || options.WIRE; // Firefox Win: it just doesn't crash sometimes. function crash(pageImpl, browserName) { if (browserName === 'chromium') diff --git a/test/page-event-network.spec.ts b/test/page-event-network.spec.ts index 33746c88533fe..80485cefd243a 100644 --- a/test/page-event-network.spec.ts +++ b/test/page-event-network.spec.ts @@ -40,7 +40,7 @@ it('Page.Events.Response', async({page, server}) => { expect(responses[0].request()).toBeTruthy(); }); -it('Page.Events.RequestFailed', async({page, server, isChromium, isWebKit}) => { +it('Page.Events.RequestFailed', async({page, server}) => { server.setRoute('/one-style.css', (req, res) => { res.setHeader('Content-Type', 'text/css'); res.connection.destroy(); @@ -52,9 +52,9 @@ it('Page.Events.RequestFailed', async({page, server, isChromium, isWebKit}) => { expect(failedRequests[0].url()).toContain('one-style.css'); expect(await failedRequests[0].response()).toBe(null); expect(failedRequests[0].resourceType()).toBe('stylesheet'); - if (isChromium) { + if (options.CHROMIUM) { expect(failedRequests[0].failure().errorText).toBe('net::ERR_EMPTY_RESPONSE'); - } else if (isWebKit) { + } else if (options.WEBKIT) { if (MAC) expect(failedRequests[0].failure().errorText).toBe('The network connection was lost.'); else if (WIN) diff --git a/test/page-event-pageerror.spec.ts b/test/page-event-pageerror.spec.ts index 8596a3f9ff27c..737fa4a330d24 100644 --- a/test/page-event-pageerror.spec.ts +++ b/test/page-event-pageerror.spec.ts @@ -16,7 +16,7 @@ */ import './base.fixture'; -it('should fire', async({page, server, isWebKit}) => { +it('should fire', async({page, server}) => { const [error] = await Promise.all([ page.waitForEvent('pageerror'), page.goto(server.PREFIX + '/error.html'), @@ -25,7 +25,7 @@ it('should fire', async({page, server, isWebKit}) => { expect(error.message).toBe('Fancy error!'); let stack = await page.evaluate(() => window['e'].stack); // Note that WebKit reports the stack of the 'throw' statement instead of the Error constructor call. - if (isWebKit) + if (options.WEBKIT) stack = stack.replace('14:25', '15:19'); expect(error.stack).toBe(stack); }); diff --git a/test/page-goto.spec.ts b/test/page-goto.spec.ts index 53279de7183c4..6c1cf880beee6 100644 --- a/test/page-goto.spec.ts +++ b/test/page-goto.spec.ts @@ -133,7 +133,7 @@ it('should work with subframes return 204 with domcontentloaded', async({page, s await page.goto(server.PREFIX + '/frames/one-frame.html', { waitUntil: 'domcontentloaded' }); }); -it('should fail when server returns 204', async({page, server, isChromium, isWebKit}) => { +it('should fail when server returns 204', async({page, server}) => { // Webkit just loads an empty page. server.setRoute('/empty.html', (req, res) => { res.statusCode = 204; @@ -142,9 +142,9 @@ it('should fail when server returns 204', async({page, server, isChromium, isWeb let error = null; await page.goto(server.EMPTY_PAGE).catch(e => error = e); expect(error).not.toBe(null); - if (isChromium) + if (options.CHROMIUM) expect(error.message).toContain('net::ERR_ABORTED'); - else if (isWebKit) + else if (options.WEBKIT) expect(error.message).toContain('Aborted: 204 No Content'); else expect(error.message).toContain('NS_BINDING_ABORTED'); @@ -164,10 +164,10 @@ it('should work when page calls history API in beforeunload', async({page, serve expect(response.status()).toBe(200); }); -it('should fail when navigating to bad url', async({page, server, isChromium, isWebKit}) => { +it('should fail when navigating to bad url', async({page}) => { let error = null; await page.goto('asdfasdf').catch(e => error = e); - if (isChromium || isWebKit) + if (options.CHROMIUM || options.WEBKIT) expect(error.message).toContain('Cannot navigate to invalid URL'); else expect(error.message).toContain('Invalid url'); @@ -208,14 +208,14 @@ it('should throw if networkidle2 is passed as an option', async({page, server}) expect(error.message).toContain(`waitUntil: expected one of (load|domcontentloaded|networkidle)`); }); -it('should fail when main resources failed to load', async({page, server, isChromium, isWebKit}) => { +it('should fail when main resources failed to load', async({page}) => { let error = null; await page.goto('http://localhost:44123/non-existing-url').catch(e => error = e); - if (isChromium) + if (options.CHROMIUM) expect(error.message).toContain('net::ERR_CONNECTION_REFUSED'); - else if (isWebKit && WIN) + else if (options.WEBKIT && WIN) expect(error.message).toContain(`Couldn\'t connect to server`); - else if (isWebKit) + else if (options.WEBKIT) expect(error.message).toContain('Could not connect'); else expect(error.message).toContain('NS_ERROR_CONNECTION_REFUSED'); @@ -298,7 +298,7 @@ it('should disable timeout when its set to 0', async({page, server}) => { expect(loaded).toBe(true); }); -it('should fail when replaced by another navigation', async({page, server, isChromium, isWebKit}) => { +it('should fail when replaced by another navigation', async({page, server}) => { let anotherPromise; server.setRoute('/empty.html', (req, res) => { anotherPromise = page.goto(server.PREFIX + '/one-style.html'); @@ -306,9 +306,9 @@ it('should fail when replaced by another navigation', async({page, server, isChr }); const error = await page.goto(server.PREFIX + '/empty.html').catch(e => e); await anotherPromise; - if (isChromium) + if (options.CHROMIUM) expect(error.message).toContain('net::ERR_ABORTED'); - else if (isWebKit) + else if (options.WEBKIT) expect(error.message).toContain('cancelled'); else expect(error.message).toContain('NS_BINDING_ABORTED'); diff --git a/test/page-route.spec.ts b/test/page-route.spec.ts index cc410786e9127..a54d9314716ff 100644 --- a/test/page-route.spec.ts +++ b/test/page-route.spec.ts @@ -182,15 +182,15 @@ it('should be abortable', async({page, server}) => { expect(failed).toBe(true); }); -it('should be abortable with custom error codes', async({page, server, isWebKit, isFirefox}) => { +it('should be abortable with custom error codes', async({page, server}) => { await page.route('**/*', route => route.abort('internetdisconnected')); let failedRequest = null; page.on('requestfailed', request => failedRequest = request); await page.goto(server.EMPTY_PAGE).catch(e => {}); expect(failedRequest).toBeTruthy(); - if (isWebKit) + if (options.WEBKIT) expect(failedRequest.failure().errorText).toBe('Request intercepted'); - else if (isFirefox) + else if (options.FFOX) expect(failedRequest.failure().errorText).toBe('NS_ERROR_OFFLINE'); else expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED'); @@ -208,14 +208,14 @@ it('should send referer', async({page, server}) => { expect(request.headers['referer']).toBe('http://google.com/'); }); -it('should fail navigation when aborting main resource', async({page, server, isWebKit, isFirefox}) => { +it('should fail navigation when aborting main resource', async({page, server}) => { await page.route('**/*', route => route.abort()); let error = null; await page.goto(server.EMPTY_PAGE).catch(e => error = e); expect(error).toBeTruthy(); - if (isWebKit) + if (options.WEBKIT) expect(error.message).toContain('Request intercepted'); - else if (isFirefox) + else if (options.FFOX) expect(error.message).toContain('NS_ERROR_FAILURE'); else expect(error.message).toContain('net::ERR_FAILED'); diff --git a/test/page-screenshot.spec.ts b/test/page-screenshot.spec.ts index ddf1874fdc59e..d3eed9734b887 100644 --- a/test/page-screenshot.spec.ts +++ b/test/page-screenshot.spec.ts @@ -19,10 +19,9 @@ import utils from './utils'; import path from 'path'; import fs from 'fs'; -const { HEADLESS } = testOptions; // Firefox headful produces a different image. -const ffheadful = options.FFOX && !HEADLESS; +const ffheadful = options.FFOX && !options.HEADLESS; it.skip(ffheadful)('should work', async({page, server, golden}) => { await page.setViewportSize({width: 500, height: 500}); diff --git a/test/pdf.spec.ts b/test/pdf.spec.ts index d062c22c7d862..9169acba46ee7 100644 --- a/test/pdf.spec.ts +++ b/test/pdf.spec.ts @@ -20,10 +20,9 @@ import './base.fixture'; import fs from 'fs' import path from 'path' -const { HEADLESS } = testOptions; // Printing to pdf is currently only supported in headless chromium. -it.skip(!(HEADLESS && options.CHROMIUM))('should be able to save file', async({page, tmpDir}) => { +it.skip(!(options.HEADLESS && options.CHROMIUM))('should be able to save file', async({page, tmpDir}) => { const outputFile = path.join(tmpDir, 'output.pdf'); await page.pdf({path: outputFile}); expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0); diff --git a/test/permissions.spec.ts b/test/permissions.spec.ts index 0b58364ad270f..fa3a75dd8e46b 100644 --- a/test/permissions.spec.ts +++ b/test/permissions.spec.ts @@ -15,7 +15,6 @@ * limitations under the License. */ import './base.fixture'; -const { HEADLESS } = testOptions; function getPermission(page, name) { return page.evaluate(name => navigator.permissions.query({name}).then(result => result.state), name); @@ -92,7 +91,7 @@ describe.skip(options.WEBKIT)('permissions', () => { expect(await getPermission(page, 'geolocation')).toBe('prompt'); }); - it.fail(options.WEBKIT || options.FFOX || (options.CHROMIUM && !HEADLESS))('should trigger permission onchange', async({page, server, context}) => { + it.fail(options.WEBKIT || options.FFOX || (options.CHROMIUM && !options.HEADLESS))('should trigger permission onchange', async({page, server, context}) => { //TODO: flaky // - Linux: https://github.com/microsoft/playwright/pull/1790/checks?check_run_id=587327883 // - Win: https://ci.appveyor.com/project/aslushnikov/playwright/builds/32402536 @@ -134,7 +133,7 @@ describe.skip(options.WEBKIT)('permissions', () => { await otherContext.close(); }); - it.fail(options.WEBKIT || options.FFOX || (options.CHROMIUM && !HEADLESS))('should support clipboard read', async({page, server, context, browser}) => { + it.fail(options.WEBKIT || options.FFOX || (options.CHROMIUM && !options.HEADLESS))('should support clipboard read', async({page, server, context, browser}) => { // No such permissions (requires flag) in Firefox await page.goto(server.EMPTY_PAGE); expect(await getPermission(page, 'clipboard-read')).toBe('prompt'); diff --git a/test/popup.spec.ts b/test/popup.spec.ts index b3e70e0053fc1..f675e6e6dbc1c 100644 --- a/test/popup.spec.ts +++ b/test/popup.spec.ts @@ -209,7 +209,7 @@ it('should expose function from browser context', async function({browser, serve expect(messages.join('|')).toBe('page|binding'); }); -it('should not dispatch binding on a closed page', async function({browser, server, isFirefox}) { +it('should not dispatch binding on a closed page', async function({browser, server}) { const context = await browser.newContext(); const messages = []; await context.exposeFunction('add', (a, b) => { @@ -232,7 +232,7 @@ it('should not dispatch binding on a closed page', async function({browser, serv }), ]); await context.close(); - if (isFirefox) + if (options.FFOX) expect(messages.join('|')).toBe('alreadyclosed'); else expect(messages.join('|')).toBe('binding|close'); diff --git a/test/proxy.spec.ts b/test/proxy.spec.ts index cad91d8ccd9f8..e9f7ad8a49a94 100644 --- a/test/proxy.spec.ts +++ b/test/proxy.spec.ts @@ -19,7 +19,6 @@ import './base.fixture'; import socks from 'socksv5'; -const { HEADLESS } = testOptions; it('should use proxy', async ({browserType, defaultBrowserOptions, server}) => { server.setRoute('/target.html', async (req, res) => { @@ -57,7 +56,7 @@ it('should authenticate', async ({browserType, defaultBrowserOptions, server}) = await browser.close(); }); -it.fail(options.CHROMIUM && !HEADLESS)('should exclude patterns', async ({browserType, defaultBrowserOptions, server}) => { +it.fail(options.CHROMIUM && !options.HEADLESS)('should exclude patterns', async ({browserType, defaultBrowserOptions, server}) => { // Chromium headful crashes with CHECK(!in_frame_tree_) in RenderFrameImpl::OnDeleteFrame. server.setRoute('/target.html', async (req, res) => { res.end('Served by the proxy'); diff --git a/test/request-fulfill.spec.ts b/test/request-fulfill.spec.ts index cd6f603693347..80a447270169f 100644 --- a/test/request-fulfill.spec.ts +++ b/test/request-fulfill.spec.ts @@ -19,7 +19,6 @@ import './base.fixture'; import fs from 'fs'; import path from 'path'; -const { HEADLESS } = testOptions; it('should work', async({page, server}) => { await page.route('**/*', route => { @@ -51,7 +50,7 @@ it('should work with status code 422', async({page, server}) => { expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!'); }); -it.skip(options.FFOX && !HEADLESS)('should allow mocking binary responses', async({page, server, golden}) => { +it.skip(options.FFOX && !options.HEADLESS)('should allow mocking binary responses', async({page, server, golden}) => { // Firefox headful produces a different image. await page.route('**/*', route => { const imageBuffer = fs.readFileSync(path.join(__dirname, 'assets', 'pptr.png')); @@ -70,7 +69,7 @@ it.skip(options.FFOX && !HEADLESS)('should allow mocking binary responses', asyn expect(await img.screenshot()).toMatchImage(golden('mock-binary-response.png')); }); -it.skip(options.FFOX && !HEADLESS)('should allow mocking svg with charset', async({page, server, golden}) => { +it.skip(options.FFOX && !options.HEADLESS)('should allow mocking svg with charset', async({page, server, golden}) => { // Firefox headful produces a different image. await page.route('**/*', route => { route.fulfill({ diff --git a/test/runner/fixtures.js b/test/runner/fixtures.js index 7e0a6db41d1e5..7bf13bc3af445 100644 --- a/test/runner/fixtures.js +++ b/test/runner/fixtures.js @@ -204,6 +204,11 @@ function registerWorkerFixture(name, fn) { innerRegisterFixture(name, 'worker', fn); }; +function registerOptionGenerator(name, fn) { + registerWorkerFixture(name, async ({}, test) => await test(options.browserName)); + optionRegistrations.set(name, fn); +} + function registerOption(name, fn) { optionRegistrations.set(name, fn); } @@ -256,4 +261,4 @@ function computeWorkerHash(file) { return hash.digest('hex'); } -module.exports = { FixturePool, registerFixture, registerWorkerFixture, computeWorkerHash, rerunRegistrations, lookupRegistrations, fixturesForCallback, registerOption, setOptions, optionRegistrations, options }; +module.exports = { FixturePool, registerFixture, registerWorkerFixture, computeWorkerHash, rerunRegistrations, lookupRegistrations, fixturesForCallback, registerOption, registerOptionGenerator, setOptions, optionRegistrations, options }; diff --git a/test/runner/fixturesUI.js b/test/runner/fixturesUI.js index 86afb7dc468ae..8cb6c7eac233e 100644 --- a/test/runner/fixturesUI.js +++ b/test/runner/fixturesUI.js @@ -21,7 +21,6 @@ const commonSuite = require('mocha/lib/interfaces/common'); Error.stackTraceLimit = 15; global.options = options; -global.testOptions = require('./testOptions'); global.registerFixture = registerFixture; global.registerWorkerFixture = registerWorkerFixture; global.registerOption = registerOption; diff --git a/test/runner/testCollector.js b/test/runner/testCollector.js index 7a520a375bd6a..cd28fa62bea3a 100644 --- a/test/runner/testCollector.js +++ b/test/runner/testCollector.js @@ -19,8 +19,6 @@ const Mocha = require('mocha'); const { fixturesForCallback, optionRegistrations } = require('./fixtures'); const { fixturesUI } = require('./fixturesUI'); -global.testOptions = require('./testOptions'); - class NullReporter {} class TestCollector { diff --git a/test/runner/testOptions.js b/test/runner/testOptions.js deleted file mode 100644 index 3215748b51080..0000000000000 --- a/test/runner/testOptions.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright Microsoft Corporation. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -const os = require('os'); -const { valueFromEnv } = require('./utils'); - -const testOptions = {}; -testOptions.WIRE = process.env.PWWIRE; -testOptions.HEADLESS = !!valueFromEnv('HEADLESS', true); - -module.exports = testOptions; diff --git a/test/runner/testRunner.js b/test/runner/testRunner.js index 95c27e2713bec..9a062f79005bb 100644 --- a/test/runner/testRunner.js +++ b/test/runner/testRunner.js @@ -22,7 +22,6 @@ const { EventEmitter } = require('events'); const fixturePool = new FixturePool(); global.expect = require('expect'); -global.testOptions = require('./testOptions'); const GoldenUtils = require('./GoldenUtils'); class NullReporter {} diff --git a/test/screencast.spec.ts b/test/screencast.spec.ts index a10dc6b3513e8..e2bf1876bfe54 100644 --- a/test/screencast.spec.ts +++ b/test/screencast.spec.ts @@ -23,7 +23,6 @@ import fs from 'fs'; import path from 'path'; import url from 'url'; -const { HEADLESS } = testOptions; declare global { interface FixtureState { @@ -182,7 +181,7 @@ it.fail(options.CHROMIUM)('should capture static page', async({page, tmpDir, vid await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 640, height: 480}); // TODO: in WebKit figure out why video size is not reported correctly for // static pictures. - if (HEADLESS && options.WEBKIT) + if (options.HEADLESS && options.WEBKIT) await page.setViewportSize({width: 1270, height: 950}); await new Promise(r => setTimeout(r, 300)); await toImpl(page)._delegate.stopScreencast(); @@ -208,7 +207,7 @@ it.fail(options.CHROMIUM)('should capture navigation', async({page, tmpDir, serv await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 640, height: 480}); // TODO: in WebKit figure out why video size is not reported correctly for // static pictures. - if (HEADLESS && options.WEBKIT) + if (options.HEADLESS && options.WEBKIT) await page.setViewportSize({width: 1270, height: 950}); await new Promise(r => setTimeout(r, 300)); await page.goto(server.CROSS_PROCESS_PREFIX + '/background-color.html#rgb(100,100,100)'); @@ -242,7 +241,7 @@ it.fail(options.CHROMIUM || (options.WEBKIT && WIN))('should capture css transfo await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 640, height: 480}); // TODO: in WebKit figure out why video size is not reported correctly for // static pictures. - if (HEADLESS && options.WEBKIT) + if (options.HEADLESS && options.WEBKIT) await page.setViewportSize({width: 1270, height: 950}); await new Promise(r => setTimeout(r, 300)); await toImpl(page)._delegate.stopScreencast(); diff --git a/test/slowmo.spec.ts b/test/slowmo.spec.ts index fb9c92897f6b7..efe7a249f487a 100644 --- a/test/slowmo.spec.ts +++ b/test/slowmo.spec.ts @@ -17,8 +17,6 @@ import './base.fixture'; import { attachFrame } from './utils'; -const {WIRE} = testOptions; - async function checkSlowMo(toImpl, page, task) { let didSlowMo = false; const orig = toImpl(page)._doSlowMo; @@ -47,67 +45,67 @@ async function checkPageSlowMo(toImpl, page, task) { await checkSlowMo(toImpl, page, task); } -it.skip(WIRE)('Page SlowMo $$eval', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo $$eval', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.$$eval('button', () => void 0)); }); -it.skip(WIRE)('Page SlowMo $eval', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo $eval', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.$eval('button', () => void 0)); }); -it.skip(WIRE)('Page SlowMo check', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo check', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.check('.check')); }); -it.skip(WIRE)('Page SlowMo click', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo click', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.click('button')); }); -it.skip(WIRE)('Page SlowMo dblclick', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo dblclick', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.dblclick('button')); }); -it.skip(WIRE)('Page SlowMo dispatchEvent', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo dispatchEvent', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.dispatchEvent('button', 'click')); }); -it.skip(WIRE)('Page SlowMo emulateMedia', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo emulateMedia', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.emulateMedia({media: 'print'})); }); -it.skip(WIRE)('Page SlowMo evaluate', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo evaluate', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.evaluate(() => void 0)); }); -it.skip(WIRE)('Page SlowMo evaluateHandle', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo evaluateHandle', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.evaluateHandle(() => window)); }); -it.skip(WIRE)('Page SlowMo fill', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo fill', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.fill('.fill', 'foo')); }); -it.skip(WIRE)('Page SlowMo focus', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo focus', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.focus('button')); }); -it.skip(WIRE)('Page SlowMo goto', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo goto', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.goto('about:blank')); }); -it.skip(WIRE)('Page SlowMo hover', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo hover', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.hover('button')); }); -it.skip(WIRE)('Page SlowMo press', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo press', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.press('button', 'Enter')); }); -it.skip(WIRE)('Page SlowMo reload', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo reload', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.reload()); }); -it.skip(WIRE)('Page SlowMo setContent', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo setContent', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.setContent('hello world')); }); -it.skip(WIRE)('Page SlowMo selectOption', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo selectOption', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.selectOption('select', 'foo')); }); -it.skip(WIRE)('Page SlowMo setInputFiles', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo setInputFiles', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.setInputFiles('.file', [])); }); -it.skip(WIRE)('Page SlowMo setViewportSize', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo setViewportSize', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.setViewportSize({height: 400, width: 400})); }); -it.skip(WIRE)('Page SlowMo type', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo type', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.type('.fill', 'a')); }); -it.skip(WIRE)('Page SlowMo uncheck', async ({page, toImpl}) => { +it.skip(options.WIRE)('Page SlowMo uncheck', async ({page, toImpl}) => { await checkPageSlowMo(toImpl, page, () => page.uncheck('.uncheck')); }); @@ -126,58 +124,58 @@ async function checkFrameSlowMo(toImpl, page, server, task) { await checkSlowMo(toImpl, page, task.bind(null, frame)); } -it.skip(WIRE)('Frame SlowMo $$eval', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo $$eval', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.$$eval('button', () => void 0)); }); -it.skip(WIRE)('Frame SlowMo $eval', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo $eval', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.$eval('button', () => void 0)); }); -it.skip(WIRE)('Frame SlowMo check', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo check', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.check('.check')); }); -it.skip(WIRE)('Frame SlowMo click', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo click', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.click('button')); }); -it.skip(WIRE)('Frame SlowMo dblclick', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo dblclick', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.dblclick('button')); }); -it.skip(WIRE)('Frame SlowMo dispatchEvent', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo dispatchEvent', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.dispatchEvent('button', 'click')); }); -it.skip(WIRE)('Frame SlowMo evaluate', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo evaluate', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.evaluate(() => void 0)); }); -it.skip(WIRE)('Frame SlowMo evaluateHandle', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo evaluateHandle', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.evaluateHandle(() => window)); }); -it.skip(WIRE)('Frame SlowMo fill', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo fill', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.fill('.fill', 'foo')); }); -it.skip(WIRE)('Frame SlowMo focus', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo focus', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.focus('button')); }); -it.skip(WIRE)('Frame SlowMo goto', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo goto', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.goto('about:blank')); }); -it.skip(WIRE)('Frame SlowMo hover', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo hover', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.hover('button')); }); -it.skip(WIRE)('Frame SlowMo press', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo press', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.press('button', 'Enter')); }); -it.skip(WIRE)('Frame SlowMo setContent', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo setContent', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.setContent('hello world')); }); -it.skip(WIRE)('Frame SlowMo selectOption', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo selectOption', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.selectOption('select', 'foo')); }); -it.skip(WIRE)('Frame SlowMo setInputFiles', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo setInputFiles', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.setInputFiles('.file', [])); }); -it.skip(WIRE)('Frame SlowMo type', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo type', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.type('.fill', 'a')); }); -it.skip(WIRE)('Frame SlowMo uncheck', async({page, server, toImpl}) => { +it.skip(options.WIRE)('Frame SlowMo uncheck', async({page, server, toImpl}) => { await checkFrameSlowMo(toImpl, page, server, frame => frame.uncheck('.uncheck')); }); @@ -195,51 +193,51 @@ async function checkElementSlowMo(toImpl, page, selector, task) { const element = await page.$(selector); await checkSlowMo(toImpl, page, task.bind(null, element)); } -it.skip(WIRE)('ElementHandle SlowMo $$eval', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo $$eval', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'body', element => element.$$eval('button', () => void 0)); }); -it.skip(WIRE)('ElementHandle SlowMo $eval', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo $eval', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'body', element => element.$eval('button', () => void 0)); }); -it.skip(WIRE)('ElementHandle SlowMo check', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo check', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, '.check', element => element.check()); }); -it.skip(WIRE)('ElementHandle SlowMo click', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo click', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.click()); }); -it.skip(WIRE)('ElementHandle SlowMo dblclick', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo dblclick', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.dblclick()); }); -it.skip(WIRE)('ElementHandle SlowMo dispatchEvent', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo dispatchEvent', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.dispatchEvent('click')); }); -it.skip(WIRE)('ElementHandle SlowMo evaluate', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo evaluate', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.evaluate(() => void 0)); }); -it.skip(WIRE)('ElementHandle SlowMo evaluateHandle', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo evaluateHandle', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.evaluateHandle(() => void 0)); }); -it.skip(WIRE)('ElementHandle SlowMo fill', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo fill', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, '.fill', element => element.fill('foo')); }); -it.skip(WIRE)('ElementHandle SlowMo focus', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo focus', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.focus()); }); -it.skip(WIRE)('ElementHandle SlowMo hover', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo hover', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.hover()); }); -it.skip(WIRE)('ElementHandle SlowMo press', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo press', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'button', element => element.press('Enter')); }); -it.skip(WIRE)('ElementHandle SlowMo selectOption', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo selectOption', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, 'select', element => element.selectOption('foo')); }); -it.skip(WIRE)('ElementHandle SlowMo setInputFiles', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo setInputFiles', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, '.file', element => element.setInputFiles([])); }); -it.skip(WIRE)('ElementHandle SlowMo type', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo type', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, '.fill', element => element.type( 'a')); }); -it.skip(WIRE)('ElementHandle SlowMo uncheck', async ({page, toImpl}) => { +it.skip(options.WIRE)('ElementHandle SlowMo uncheck', async ({page, toImpl}) => { await checkElementSlowMo(toImpl, page, '.uncheck', element => element.uncheck()); }); diff --git a/test/types.d.ts b/test/types.d.ts index 79696e6f20b17..5c476a27cc8ee 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -68,12 +68,6 @@ declare const afterAll: (inner: (state: WorkerState) => Promise) => void; declare const browserType: import('../index').BrowserType; -// global variables in assets -declare const testOptions: { - HEADLESS: boolean; - WIRE: boolean; -}; - declare var MAC: boolean; declare var LINUX: boolean; declare var WIN: boolean;