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: update fixtures to new syntax (#4063)
Dmitry Gozmane403fd391208
diff --git a/test/chromium/oopif.spec.ts b/test/chromium/oopif.spec.tsindex eec022419b..e8563184af 100644--- a/test/chromium/oopif.spec.ts+++ b/test/chromium/oopif.spec.ts@@ -15,9 +15,8 @@*/import { fixtures as playwrightFixtures } from '../fixtures';-const { it, expect, describe, overrideWorkerFixtures } = playwrightFixtures;-overrideWorkerFixtures({+const fixtures = playwrightFixtures.overrideWorkerFixtures({browser: async ({browserType, defaultBrowserOptions}, test) => {const browser = await browserType.launch({...defaultBrowserOptions,@@ -28,6 +27,8 @@ overrideWorkerFixtures({}});+const { it, expect, describe } = fixtures;+describe('oopif', (suite, { browserName }) => {suite.skip(browserName !== 'chromium');}, () => {diff --git a/test/fixtures.ts b/test/fixtures.tsindex f0db339325..e4109bc0f0 100644--- a/test/fixtures.ts+++ b/test/fixtures.ts@@ -32,6 +32,15 @@ export { expect, config } from '@playwright/test-runner';const removeFolderAsync = util.promisify(require('rimraf'));const mkdtempAsync = util.promisify(fs.mkdtemp);+const getExecutablePath = browserName => {+ if (browserName === 'chromium' && process.env.CRPATH)+ return process.env.CRPATH;+ if (browserName === 'firefox' && process.env.FFPATH)+ return process.env.FFPATH;+ if (browserName === 'webkit' && process.env.WKPATH)+ return process.env.WKPATH;+};+type AllTestFixtures = {createUserDataDir: () => Promise<string>;launchPersistent: (options?: Parameters<BrowserType<Browser>['launchPersistentContext']>[1]) => Promise<{ context: BrowserContext, page: Page }>;@@ -73,8 +82,70 @@ export const fixtures = playwrightFixturesif (context)await context.close();},+ })+ .overrideWorkerFixtures({+ defaultBrowserOptions: async ({ browserName, headful, slowMo }, runTest) => {+ const executablePath = getExecutablePath(browserName);+ if (executablePath)+ console.error(`Using executable at ${executablePath}`);+ await runTest({+ executablePath,+ handleSIGINT: false,+ slowMo,+ headless: !headful,+ });+ },++ playwright: async ({ browserName, testWorkerIndex, platform, wire }, runTest) => {+ assert(platform); // Depend on platform to generate all tests.+ const { coverage, uninstall } = installCoverageHooks(browserName);+ if (wire) {+ require('../lib/utils/utils').setUnderTest();+ const connection = new Connection();+ const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'driver.js'), ['serve'], {+ stdio: 'pipe',+ detached: true,+ });+ spawnedProcess.unref();+ const onExit = (exitCode, signal) => {+ throw new Error(`Server closed with exitCode=${exitCode} signal=${signal}`);+ };+ spawnedProcess.on('exit', onExit);+ const transport = new Transport(spawnedProcess.stdin, spawnedProcess.stdout);+ connection.onmessage = message => transport.send(JSON.stringify(message));+ transport.onmessage = message => connection.dispatch(JSON.parse(message));+ const playwrightObject = await connection.waitForObjectWithKnownName('Playwright');+ await runTest(playwrightObject);+ spawnedProcess.removeListener('exit', onExit);+ spawnedProcess.stdin.destroy();+ spawnedProcess.stdout.destroy();+ spawnedProcess.stderr.destroy();+ await teardownCoverage();+ } else {+ const playwright = require('../index');+ await runTest(playwright);+ await teardownCoverage();+ }++ async function teardownCoverage() {+ uninstall();+ const coveragePath = path.join(__dirname, 'coverage-report', testWorkerIndex + '.json');+ const coverageJSON = [...coverage.keys()].filter(key => coverage.get(key));+ await fs.promises.mkdir(path.dirname(coveragePath), { recursive: true });+ await fs.promises.writeFile(coveragePath, JSON.stringify(coverageJSON, undefined, 2), 'utf8');+ }+ },+ })+ .overrideTestFixtures({+ testParametersPathSegment: async ({ browserName }, runTest) => {+ await runTest(browserName);+ }});+fixtures.generateParametrizedTests(+ 'platform',+ process.env.PWTESTREPORT ? ['win32', 'darwin', 'linux'] : [process.platform as ('win32' | 'linux' | 'darwin')]);+export const it = fixtures.it;export const fit = fixtures.fit;export const xit = fixtures.xit;@@ -85,77 +156,3 @@ export const beforeEach = fixtures.beforeEach;export const afterEach = fixtures.afterEach;export const beforeAll = fixtures.beforeAll;export const afterAll = fixtures.afterAll;---fixtures.generateParametrizedTests(- 'platform',- process.env.PWTESTREPORT ? ['win32', 'darwin', 'linux'] : [process.platform as ('win32' | 'linux' | 'darwin')]);--const getExecutablePath = browserName => {- if (browserName === 'chromium' && process.env.CRPATH)- return process.env.CRPATH;- if (browserName === 'firefox' && process.env.FFPATH)- return process.env.FFPATH;- if (browserName === 'webkit' && process.env.WKPATH)- return process.env.WKPATH;-};--fixtures.overrideWorkerFixtures({- defaultBrowserOptions: async ({ browserName, headful, slowMo }, runTest) => {- const executablePath = getExecutablePath(browserName);- if (executablePath)- console.error(`Using executable at ${executablePath}`);- await runTest({- executablePath,- handleSIGINT: false,- slowMo,- headless: !headful,- });- },-- playwright: async ({ browserName, testWorkerIndex, platform, wire }, runTest) => {- assert(platform); // Depend on platform to generate all tests.- const { coverage, uninstall } = installCoverageHooks(browserName);- if (wire) {- require('../lib/utils/utils').setUnderTest();- const connection = new Connection();- const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'driver.js'), ['serve'], {- stdio: 'pipe',- detached: true,- });- spawnedProcess.unref();- const onExit = (exitCode, signal) => {- throw new Error(`Server closed with exitCode=${exitCode} signal=${signal}`);- };- spawnedProcess.on('exit', onExit);- const transport = new Transport(spawnedProcess.stdin, spawnedProcess.stdout);- connection.onmessage = message => transport.send(JSON.stringify(message));- transport.onmessage = message => connection.dispatch(JSON.parse(message));- const playwrightObject = await connection.waitForObjectWithKnownName('Playwright');- await runTest(playwrightObject);- spawnedProcess.removeListener('exit', onExit);- spawnedProcess.stdin.destroy();- spawnedProcess.stdout.destroy();- spawnedProcess.stderr.destroy();- await teardownCoverage();- } else {- const playwright = require('../index');- await runTest(playwright);- await teardownCoverage();- }-- async function teardownCoverage() {- uninstall();- const coveragePath = path.join(__dirname, 'coverage-report', testWorkerIndex + '.json');- const coverageJSON = [...coverage.keys()].filter(key => coverage.get(key));- await fs.promises.mkdir(path.dirname(coveragePath), { recursive: true });- await fs.promises.writeFile(coveragePath, JSON.stringify(coverageJSON, undefined, 2), 'utf8');- }- },-});--fixtures.overrideTestFixtures({- testParametersPathSegment: async ({ browserName }, runTest) => {- await runTest(browserName);- }-});diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.tsindex 2c857f4e0c..662a3249d0 100644--- a/test/playwright.fixtures.ts+++ b/test/playwright.fixtures.ts@@ -59,12 +59,12 @@ type PlaywrightTestFixtures = {};export const fixtures = baseFixtures- .defineParameter<'browserName', 'chromium' | 'firefox' | 'webkit'>('browserName', 'Browser type name', process.env.BROWSER || 'chromium' as any)- .defineParameter<'headful', boolean>('headful', 'Whether to run tests headless or headful', process.env.HEADFUL ? true : false)- .defineParameter<'platform', 'win32' | 'linux' | 'darwin'>('platform', 'Operating system', process.platform as ('win32' | 'linux' | 'darwin'))- .defineParameter<'screenshotOnFailure', boolean>('screenshotOnFailure', 'Generate screenshot on failure', false)- .defineParameter<'slowMo', number>('slowMo', 'Slows down Playwright operations by the specified amount of milliseconds', 0)- .defineParameter<'trace', boolean>('trace', 'Whether to record the execution trace', !!process.env.TRACING || false)+ .defineParameter('browserName', 'Browser type name', (process.env.BROWSER || 'chromium') as 'chromium' | 'firefox' | 'webkit')+ .defineParameter('headful', 'Whether to run tests headless or headful', process.env.HEADFUL ? true : false)+ .defineParameter('platform', 'Operating system', process.platform as ('win32' | 'linux' | 'darwin'))+ .defineParameter('screenshotOnFailure', 'Generate screenshot on failure', false)+ .defineParameter('slowMo', 'Slows down Playwright operations by the specified amount of milliseconds', 0)+ .defineParameter('trace', 'Whether to record the execution trace', !!process.env.TRACING || false).defineWorkerFixtures<PlaywrightWorkerFixtures>({defaultBrowserOptions: async ({ headful, slowMo }, runTest) => {await runTest({@@ -159,16 +159,14 @@ export const fixtures = baseFixturesawait runTest(await context.newPage());// Context fixture is taking care of closing the page.},+ })+ .overrideTestFixtures({+ testParametersPathSegment: async ({ browserName, platform }, runTest) => {+ await runTest(browserName + '-' + platform);+ }});// If browser is not specified, we are running tests against all three browsers.fixtures.generateParametrizedTests('browserName',process.env.BROWSER ? [process.env.BROWSER] as any : ['chromium', 'webkit', 'firefox']);---fixtures.overrideTestFixtures({- testParametersPathSegment: async ({ browserName, platform }, runTest) => {- await runTest(browserName + '-' + platform);- }-});