From 0ee9050f1bb9406775438cc52e4c8599a5f266d4 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Sat, 26 Sep 2020 10:59:27 -0700 Subject: [PATCH] chore: split playwright.fixtures into files (4) (#3985) --- package-lock.json | 30 ++- test/accessibility.spec.ts | 2 +- test/autowaiting-basic.spec.ts | 2 +- test/autowaiting-no-hang.spec.ts | 2 +- test/browser.spec.ts | 2 +- test/browsercontext-add-cookies.spec.ts | 2 +- test/browsercontext-basic.spec.ts | 2 +- test/browsercontext-clearcookies.spec.ts | 2 +- test/browsercontext-cookies.spec.ts | 2 +- test/browsercontext-credentials.spec.ts | 2 +- test/browsercontext-csp.spec.ts | 2 +- test/browsercontext-device.spec.ts | 2 +- test/browsercontext-expose-function.spec.ts | 2 +- test/browsercontext-locale.spec.ts | 2 +- test/browsercontext-page-event.spec.ts | 2 +- test/browsercontext-route.spec.ts | 2 +- test/browsercontext-timezone-id.spec.ts | 2 +- test/browsercontext-user-agent.spec.ts | 2 +- test/browsercontext-viewport-mobile.spec.ts | 2 +- test/browsercontext-viewport.spec.ts | 2 +- test/browsertype-basic.spec.ts | 2 +- test/browsertype-connect.spec.ts | 2 +- test/browsertype-launch-server.spec.ts | 2 +- test/browsertype-launch.spec.ts | 2 +- test/capabilities.spec.ts | 2 +- test/channels.spec.ts | 2 +- test/check.spec.ts | 2 +- test/chromium-css-coverage.spec.ts | 2 +- test/chromium-js-coverage.spec.ts | 2 +- test/chromium/chromium.spec.ts | 2 +- test/chromium/launcher.spec.ts | 2 +- test/chromium/oopif.spec.ts | 2 +- test/chromium/session.spec.ts | 2 +- test/chromium/tracing.spec.ts | 2 +- test/click-react.spec.ts | 2 +- test/click-timeout-1.spec.ts | 2 +- test/click-timeout-2.spec.ts | 2 +- test/click-timeout-3.spec.ts | 2 +- test/click-timeout-4.spec.ts | 2 +- test/click.spec.ts | 2 +- test/defaultbrowsercontext-1.spec.ts | 2 +- test/defaultbrowsercontext-2.spec.ts | 2 +- test/dialog.spec.ts | 2 +- test/dispatchevent.spec.ts | 2 +- test/download.spec.ts | 2 +- test/downloads-path.spec.ts | 2 +- test/electron/electron-app.spec.ts | 2 +- test/electron/electron-window.spec.ts | 2 +- test/electron/electron.fixture.ts | 2 +- test/elementhandle-bounding-box.spec.ts | 2 +- test/elementhandle-click.spec.ts | 2 +- test/elementhandle-content-frame.spec.ts | 2 +- test/elementhandle-convenience.spec.ts | 2 +- test/elementhandle-eval-on-selector.spec.ts | 2 +- test/elementhandle-misc.spec.ts | 2 +- test/elementhandle-owner-frame.spec.ts | 2 +- test/elementhandle-press.spec.ts | 2 +- test/elementhandle-query-selector.spec.ts | 2 +- test/elementhandle-screenshot.spec.ts | 2 +- test/elementhandle-scroll-into-view.spec.ts | 2 +- test/elementhandle-select-text.spec.ts | 2 +- test/elementhandle-type.spec.ts | 2 +- ...ementhandle-wait-for-element-state.spec.ts | 2 +- test/emulation-focus.spec.ts | 2 +- test/eval-on-selector-all.spec.ts | 2 +- test/eval-on-selector.spec.ts | 2 +- test/firefox/launcher.spec.ts | 2 +- test/fixtures.spec.ts | 2 +- test/fixtures.ts | 170 ++++++++++++++ test/focus.spec.ts | 2 +- test/frame-evaluate.spec.ts | 2 +- test/frame-frame-element.spec.ts | 2 +- test/frame-goto.spec.ts | 2 +- test/frame-hierarchy.spec.ts | 2 +- test/geolocation.spec.ts | 2 +- test/headful.spec.ts | 2 +- test/ignorehttpserrors.spec.ts | 2 +- test/impl.fixtures.ts | 2 +- test/interception.spec.ts | 2 +- test/jshandle-as-element.spec.ts | 2 +- test/jshandle-evaluate.spec.ts | 2 +- test/jshandle-json-value.spec.ts | 2 +- test/jshandle-properties.spec.ts | 2 +- test/jshandle-to-string.spec.ts | 2 +- test/keyboard.spec.ts | 2 +- test/launcher.spec.ts | 2 +- test/logger.spec.ts | 2 +- test/mouse.spec.ts | 2 +- test/navigation.spec.ts | 2 +- test/network-request.spec.ts | 2 +- test/network-response.spec.ts | 2 +- test/page-add-init-script.spec.ts | 2 +- test/page-add-script-tag.spec.ts | 2 +- test/page-add-style-tag.spec.ts | 2 +- test/page-basic.spec.ts | 2 +- test/page-emulate-media.spec.ts | 2 +- test/page-evaluate-handle.spec.ts | 2 +- test/page-evaluate.spec.ts | 2 +- test/page-event-console.spec.ts | 2 +- test/page-event-crash.spec.ts | 2 +- test/page-event-network.spec.ts | 2 +- test/page-event-pageerror.spec.ts | 2 +- test/page-event-popup.spec.ts | 2 +- test/page-event-request.spec.ts | 2 +- test/page-expose-function.spec.ts | 2 +- test/page-fill.spec.ts | 2 +- test/page-goto.spec.ts | 2 +- test/page-history.spec.ts | 2 +- test/page-network-idle.spec.ts | 2 +- test/page-route.spec.ts | 2 +- test/page-screenshot.spec.ts | 2 +- test/page-select-option.spec.ts | 2 +- test/page-set-content.spec.ts | 2 +- test/page-set-extra-http-headers.spec.ts | 2 +- test/page-set-input-files.spec.ts | 2 +- test/page-wait-for-load-state.spec.ts | 2 +- test/page-wait-for-navigation.spec.ts | 2 +- test/page-wait-for-request.spec.ts | 2 +- test/page-wait-for-response.spec.ts | 2 +- test/pdf.spec.ts | 2 +- test/permissions.spec.ts | 2 +- test/playwright.fixtures.ts | 218 ++++++++---------- test/popup.spec.ts | 2 +- test/proxy.spec.ts | 2 +- test/queryselector.spec.ts | 2 +- test/remoteServer.fixture.ts | 2 +- test/request-continue.spec.ts | 2 +- test/request-fulfill.spec.ts | 2 +- test/screencast.spec.ts | 2 +- test/selectors-css.spec.ts | 2 +- test/selectors-misc.spec.ts | 2 +- test/selectors-register.spec.ts | 2 +- test/selectors-text.spec.ts | 2 +- test/slowmo.spec.ts | 2 +- test/trace.spec.ts | 2 +- test/upstream.fixtures.ts | 153 ------------ test/utils.ts | 2 +- test/wait-for-function.spec.ts | 2 +- test/wait-for-selector-1.spec.ts | 2 +- test/wait-for-selector-2.spec.ts | 2 +- test/workers.spec.ts | 2 +- 141 files changed, 435 insertions(+), 410 deletions(-) create mode 100644 test/fixtures.ts delete mode 100644 test/upstream.fixtures.ts diff --git a/package-lock.json b/package-lock.json index e3f4b75098..ab6fb9016c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2029,6 +2029,16 @@ "dev": true, "optional": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -3718,6 +3728,13 @@ "flat-cache": "^2.0.1" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true, + "optional": true + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -5371,6 +5388,13 @@ "readable-stream": "^2.0.5" } }, + "nan": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", + "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==", + "dev": true, + "optional": true + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -7785,7 +7809,11 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "dev": true, - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "glob-parent": { "version": "3.1.0", diff --git a/test/accessibility.spec.ts b/test/accessibility.spec.ts index f172a4955e..6120b3cca3 100644 --- a/test/accessibility.spec.ts +++ b/test/accessibility.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; it('should work', async ({ page, isFirefox, isChromium }) => { await page.setContent(` diff --git a/test/autowaiting-basic.spec.ts b/test/autowaiting-basic.spec.ts index 63bef1fb29..a86b3a21f8 100644 --- a/test/autowaiting-basic.spec.ts +++ b/test/autowaiting-basic.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should await navigation when clicking anchor', async ({page, server}) => { const messages = []; diff --git a/test/autowaiting-no-hang.spec.ts b/test/autowaiting-no-hang.spec.ts index d8bf095660..0a6a278d91 100644 --- a/test/autowaiting-no-hang.spec.ts +++ b/test/autowaiting-no-hang.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it } from './playwright.fixtures'; +import { it } from './fixtures'; it('clicking on links which do not commit navigation', async ({page, server, httpsServer}) => { await page.goto(server.EMPTY_PAGE); diff --git a/test/browser.spec.ts b/test/browser.spec.ts index f9a36062d8..0985a1e16a 100644 --- a/test/browser.spec.ts +++ b/test/browser.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should create new page', async function({browser}) { const page1 = await browser.newPage(); diff --git a/test/browsercontext-add-cookies.spec.ts b/test/browsercontext-add-cookies.spec.ts index 175d35f014..6cadbab653 100644 --- a/test/browsercontext-add-cookies.spec.ts +++ b/test/browsercontext-add-cookies.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({context, page, server}) => { await page.goto(server.EMPTY_PAGE); diff --git a/test/browsercontext-basic.spec.ts b/test/browsercontext-basic.spec.ts index 26841ca222..c98fad895c 100644 --- a/test/browsercontext-basic.spec.ts +++ b/test/browsercontext-basic.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { verifyViewport } from './utils'; it('should create new context', async function({browser}) { diff --git a/test/browsercontext-clearcookies.spec.ts b/test/browsercontext-clearcookies.spec.ts index 345034d946..43a58bc2c8 100644 --- a/test/browsercontext-clearcookies.spec.ts +++ b/test/browsercontext-clearcookies.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should clear cookies', async ({context, page, server}) => { await page.goto(server.EMPTY_PAGE); diff --git a/test/browsercontext-cookies.spec.ts b/test/browsercontext-cookies.spec.ts index 6a9af49348..f71356e621 100644 --- a/test/browsercontext-cookies.spec.ts +++ b/test/browsercontext-cookies.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should return no cookies in pristine browser context', async ({context, page, server}) => { expect(await context.cookies()).toEqual([]); diff --git a/test/browsercontext-credentials.spec.ts b/test/browsercontext-credentials.spec.ts index 6ddc25103d..84917b6a4a 100644 --- a/test/browsercontext-credentials.spec.ts +++ b/test/browsercontext-credentials.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should fail without credentials', (test, parameters) => { test.fail(options.CHROMIUM(parameters) && !options.HEADLESS); diff --git a/test/browsercontext-csp.spec.ts b/test/browsercontext-csp.spec.ts index bdb3c87be1..3146e7b45d 100644 --- a/test/browsercontext-csp.spec.ts +++ b/test/browsercontext-csp.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should bypass CSP meta tag', async ({browser, server}) => { diff --git a/test/browsercontext-device.spec.ts b/test/browsercontext-device.spec.ts index f780ea0c3f..22e7111610 100644 --- a/test/browsercontext-device.spec.ts +++ b/test/browsercontext-device.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; describe('device', (suite, parameters) => { suite.skip(options.FIREFOX(parameters)); diff --git a/test/browsercontext-expose-function.spec.ts b/test/browsercontext-expose-function.spec.ts index c52fd6e6a2..eb16990b60 100644 --- a/test/browsercontext-expose-function.spec.ts +++ b/test/browsercontext-expose-function.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('expose binding should work', async ({browser}) => { const context = await browser.newContext(); diff --git a/test/browsercontext-locale.spec.ts b/test/browsercontext-locale.spec.ts index d29e0a7b49..c98aa3e6a8 100644 --- a/test/browsercontext-locale.spec.ts +++ b/test/browsercontext-locale.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should affect accept-language header', async ({browser, server}) => { const context = await browser.newContext({ locale: 'fr-CH' }); diff --git a/test/browsercontext-page-event.spec.ts b/test/browsercontext-page-event.spec.ts index 0ba24c8a72..0db153b64e 100644 --- a/test/browsercontext-page-event.spec.ts +++ b/test/browsercontext-page-event.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should have url', async ({browser, server}) => { const context = await browser.newContext(); diff --git a/test/browsercontext-route.spec.ts b/test/browsercontext-route.spec.ts index 6c806ade42..6bec90882d 100644 --- a/test/browsercontext-route.spec.ts +++ b/test/browsercontext-route.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should intercept', async ({browser, server}) => { const context = await browser.newContext(); diff --git a/test/browsercontext-timezone-id.spec.ts b/test/browsercontext-timezone-id.spec.ts index 9df30aa6ed..4e0c199726 100644 --- a/test/browsercontext-timezone-id.spec.ts +++ b/test/browsercontext-timezone-id.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({ browser }) => { const func = () => new Date(1479579154987).toString(); diff --git a/test/browsercontext-user-agent.spec.ts b/test/browsercontext-user-agent.spec.ts index ab434e690a..2cf7c390f9 100644 --- a/test/browsercontext-user-agent.spec.ts +++ b/test/browsercontext-user-agent.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should work', async ({browser, server}) => { diff --git a/test/browsercontext-viewport-mobile.spec.ts b/test/browsercontext-viewport-mobile.spec.ts index 223dc6fe9d..5d2f6ac4ff 100644 --- a/test/browsercontext-viewport-mobile.spec.ts +++ b/test/browsercontext-viewport-mobile.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; describe('mobile viewport', (suite, parameters) => { suite.skip(options.FIREFOX(parameters)); diff --git a/test/browsercontext-viewport.spec.ts b/test/browsercontext-viewport.spec.ts index aea0fed499..cfb3d6ddf9 100644 --- a/test/browsercontext-viewport.spec.ts +++ b/test/browsercontext-viewport.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { verifyViewport } from './utils'; it('should get the proper default viewport size', async ({page, server}) => { diff --git a/test/browsertype-basic.spec.ts b/test/browsertype-basic.spec.ts index d4d850bdbd..b900b37107 100644 --- a/test/browsertype-basic.spec.ts +++ b/test/browsertype-basic.spec.ts @@ -16,7 +16,7 @@ */ import fs from 'fs'; -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('browserType.executablePath should work', test => { test.skip(Boolean(process.env.CRPATH || process.env.FFPATH || process.env.WKPATH)); diff --git a/test/browsertype-connect.spec.ts b/test/browsertype-connect.spec.ts index 85bb13186a..f856a9c08e 100644 --- a/test/browsertype-connect.spec.ts +++ b/test/browsertype-connect.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { options } from './playwright.fixtures'; +import { options } from './fixtures'; import { serverFixtures } from './remoteServer.fixture'; const { it, expect, describe } = serverFixtures; diff --git a/test/browsertype-launch-server.spec.ts b/test/browsertype-launch-server.spec.ts index b2c182882a..d90a080fb0 100644 --- a/test/browsertype-launch-server.spec.ts +++ b/test/browsertype-launch-server.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; describe('lauch server', suite => { suite.skip(options.WIRE); diff --git a/test/browsertype-launch.spec.ts b/test/browsertype-launch.spec.ts index 9178ffd241..0a8769b141 100644 --- a/test/browsertype-launch.spec.ts +++ b/test/browsertype-launch.spec.ts @@ -16,7 +16,7 @@ */ import path from 'path'; -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should reject all promises when browser is closed', async ({browserType, defaultBrowserOptions}) => { const browser = await browserType.launch(defaultBrowserOptions); diff --git a/test/capabilities.spec.ts b/test/capabilities.spec.ts index 1271ef5850..ef2c1cfde8 100644 --- a/test/capabilities.spec.ts +++ b/test/capabilities.spec.ts @@ -15,7 +15,7 @@ */ import url from 'url'; -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('Web Assembly should work', (test, parameters) => { test.fail(options.WEBKIT(parameters) && options.WIN(parameters)); diff --git a/test/channels.spec.ts b/test/channels.spec.ts index 7214bccc2b..6644db98d5 100644 --- a/test/channels.spec.ts +++ b/test/channels.spec.ts @@ -16,7 +16,7 @@ */ import domain from 'domain'; -import { options, fixtures as baseFixtures } from './playwright.fixtures'; +import { options, fixtures as baseFixtures } from './fixtures'; import type { ChromiumBrowser } from '..'; type DomainFixtures = { diff --git a/test/check.spec.ts b/test/check.spec.ts index 7b360ebedf..de5a37ac34 100644 --- a/test/check.spec.ts +++ b/test/check.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should check the box', async ({page}) => { await page.setContent(``); diff --git a/test/chromium-css-coverage.spec.ts b/test/chromium-css-coverage.spec.ts index 0685eb7bc2..3d25dfff1b 100644 --- a/test/chromium-css-coverage.spec.ts +++ b/test/chromium-css-coverage.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; describe('oopif', (suite, parameters) => { suite.skip(!options.CHROMIUM(parameters)); diff --git a/test/chromium-js-coverage.spec.ts b/test/chromium-js-coverage.spec.ts index a2abba9eee..98b02560fb 100644 --- a/test/chromium-js-coverage.spec.ts +++ b/test/chromium-js-coverage.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; it('should be missing', (test, parameters) => { test.skip(options.CHROMIUM(parameters)); diff --git a/test/chromium/chromium.spec.ts b/test/chromium/chromium.spec.ts index 9dbb5fb227..25153b35f4 100644 --- a/test/chromium/chromium.spec.ts +++ b/test/chromium/chromium.spec.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect, describe, options } from '../playwright.fixtures'; +import { it, expect, describe, options } from '../fixtures'; import type { ChromiumBrowserContext } from '../..'; describe('chromium', (suite, parameters) => { diff --git a/test/chromium/launcher.spec.ts b/test/chromium/launcher.spec.ts index 3af5bb2485..449310abdf 100644 --- a/test/chromium/launcher.spec.ts +++ b/test/chromium/launcher.spec.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect, options } from '../playwright.fixtures'; +import { it, expect, options } from '../fixtures'; import path from 'path'; import type { ChromiumBrowser, ChromiumBrowserContext } from '../..'; diff --git a/test/chromium/oopif.spec.ts b/test/chromium/oopif.spec.ts index eaddee41e5..af7c6e7209 100644 --- a/test/chromium/oopif.spec.ts +++ b/test/chromium/oopif.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options, fixtures as playwrightFixtures } from '../playwright.fixtures'; +import { options, fixtures as playwrightFixtures } from '../fixtures'; const { it, expect, describe, overrideWorkerFixture } = playwrightFixtures; overrideWorkerFixture('browser', async ({browserType, defaultBrowserOptions}, test) => { diff --git a/test/chromium/session.spec.ts b/test/chromium/session.spec.ts index 97a9a8c844..34eab2641d 100644 --- a/test/chromium/session.spec.ts +++ b/test/chromium/session.spec.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect, describe, options } from '../playwright.fixtures'; +import { it, expect, describe, options } from '../fixtures'; import type { ChromiumBrowserContext, ChromiumBrowser } from '../../types/types'; describe('session', (suite, parameters) => { diff --git a/test/chromium/tracing.spec.ts b/test/chromium/tracing.spec.ts index fbde6bcf6c..f2734b3416 100644 --- a/test/chromium/tracing.spec.ts +++ b/test/chromium/tracing.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options, fixtures as playwrightFixtures } from '../playwright.fixtures'; +import { options, fixtures as playwrightFixtures } from '../fixtures'; import fs from 'fs'; import path from 'path'; import type { ChromiumBrowser } from '../..'; diff --git a/test/click-react.spec.ts b/test/click-react.spec.ts index fd4d98943c..ea29a08fd2 100644 --- a/test/click-react.spec.ts +++ b/test/click-react.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; declare const renderComponent; declare const e; diff --git a/test/click-timeout-1.spec.ts b/test/click-timeout-1.spec.ts index 6d71110e57..9278fe6e37 100644 --- a/test/click-timeout-1.spec.ts +++ b/test/click-timeout-1.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should avoid side effects after timeout', (test, parameters) => { test.skip(options.WIRE); diff --git a/test/click-timeout-2.spec.ts b/test/click-timeout-2.spec.ts index a9331a7e39..ead108a8e3 100644 --- a/test/click-timeout-2.spec.ts +++ b/test/click-timeout-2.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should timeout waiting for display:none to be gone', async ({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); diff --git a/test/click-timeout-3.spec.ts b/test/click-timeout-3.spec.ts index 67e246d5e8..f384ac8ee2 100644 --- a/test/click-timeout-3.spec.ts +++ b/test/click-timeout-3.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should fail when element jumps during hit testing', (test, parameters) => { test.skip(options.WIRE); diff --git a/test/click-timeout-4.spec.ts b/test/click-timeout-4.spec.ts index 338f16abda..c7f6cbf71f 100644 --- a/test/click-timeout-4.spec.ts +++ b/test/click-timeout-4.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should timeout waiting for stable position', async ({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); diff --git a/test/click.spec.ts b/test/click.spec.ts index 57de0ea4be..2e4bd3db7e 100644 --- a/test/click.spec.ts +++ b/test/click.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame } from './utils'; async function giveItAChanceToClick(page) { diff --git a/test/defaultbrowsercontext-1.spec.ts b/test/defaultbrowsercontext-1.spec.ts index 5fc72f56f9..4499f1d780 100644 --- a/test/defaultbrowsercontext-1.spec.ts +++ b/test/defaultbrowsercontext-1.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { verifyViewport } from './utils'; import fs from 'fs'; diff --git a/test/defaultbrowsercontext-2.spec.ts b/test/defaultbrowsercontext-2.spec.ts index 1fea3b1030..1d4848eba3 100644 --- a/test/defaultbrowsercontext-2.spec.ts +++ b/test/defaultbrowsercontext-2.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import fs from 'fs'; it('should support hasTouch option', async ({server, launchPersistent}) => { diff --git a/test/dialog.spec.ts b/test/dialog.spec.ts index 7e064e8477..a8ff4f2e22 100644 --- a/test/dialog.spec.ts +++ b/test/dialog.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should fire', async ({page, server}) => { page.on('dialog', dialog => { diff --git a/test/dispatchevent.spec.ts b/test/dispatchevent.spec.ts index a811e2193d..8786a22b84 100644 --- a/test/dispatchevent.spec.ts +++ b/test/dispatchevent.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should dispatch click event', async ({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); diff --git a/test/download.spec.ts b/test/download.spec.ts index 039aa7237d..f153d90e55 100644 --- a/test/download.spec.ts +++ b/test/download.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options } from './playwright.fixtures'; +import { options } from './fixtures'; import { serverFixtures } from './remoteServer.fixture'; const { it, expect, beforeEach } = serverFixtures; diff --git a/test/downloads-path.spec.ts b/test/downloads-path.spec.ts index 8be7b8a816..2a512e548f 100644 --- a/test/downloads-path.spec.ts +++ b/test/downloads-path.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { fixtures as baseFixtures } from './playwright.fixtures'; +import { fixtures as baseFixtures } from './fixtures'; import fs from 'fs'; import type { Browser, BrowserContext } from '..'; diff --git a/test/electron/electron-app.spec.ts b/test/electron/electron-app.spec.ts index 1771e881d9..a71d08f650 100644 --- a/test/electron/electron-app.spec.ts +++ b/test/electron/electron-app.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options } from '../playwright.fixtures'; +import { options } from '../fixtures'; import { electronFixtures } from './electron.fixture'; const { it, expect, describe } = electronFixtures; diff --git a/test/electron/electron-window.spec.ts b/test/electron/electron-window.spec.ts index e2e84166d4..1fd4464239 100644 --- a/test/electron/electron-window.spec.ts +++ b/test/electron/electron-window.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options } from '../playwright.fixtures'; +import { options } from '../fixtures'; import { electronFixtures } from './electron.fixture'; const { it, expect, describe } = electronFixtures; diff --git a/test/electron/electron.fixture.ts b/test/electron/electron.fixture.ts index 007ce394df..2bcbcc7ee7 100644 --- a/test/electron/electron.fixture.ts +++ b/test/electron/electron.fixture.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { fixtures as baseFixtures } from '../playwright.fixtures'; +import { fixtures as baseFixtures } from '../fixtures'; import type {ElectronApplication, ElectronLauncher, ElectronPage} from '../../electron-types'; import path from 'path'; diff --git a/test/elementhandle-bounding-box.spec.ts b/test/elementhandle-bounding-box.spec.ts index 68a0c6ec0c..edc06c3e8a 100644 --- a/test/elementhandle-bounding-box.spec.ts +++ b/test/elementhandle-bounding-box.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should work', (test, parameters) => { diff --git a/test/elementhandle-click.spec.ts b/test/elementhandle-click.spec.ts index 9379641257..31a5d4d3e2 100644 --- a/test/elementhandle-click.spec.ts +++ b/test/elementhandle-click.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/button.html'); diff --git a/test/elementhandle-content-frame.spec.ts b/test/elementhandle-content-frame.spec.ts index 8b6175be83..3c8df59bbf 100644 --- a/test/elementhandle-content-frame.spec.ts +++ b/test/elementhandle-content-frame.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should work', async ({ page, server }) => { diff --git a/test/elementhandle-convenience.spec.ts b/test/elementhandle-convenience.spec.ts index 7d1c01a1b3..5b3e2aaeb0 100644 --- a/test/elementhandle-convenience.spec.ts +++ b/test/elementhandle-convenience.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should have a nice preview', async ({ page, server }) => { await page.goto(`${server.PREFIX}/dom.html`); diff --git a/test/elementhandle-eval-on-selector.spec.ts b/test/elementhandle-eval-on-selector.spec.ts index 2e9ba77787..008a53164d 100644 --- a/test/elementhandle-eval-on-selector.spec.ts +++ b/test/elementhandle-eval-on-selector.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server}) => { await page.setContent('
10
'); diff --git a/test/elementhandle-misc.spec.ts b/test/elementhandle-misc.spec.ts index 79ec109432..e343e5aeaf 100644 --- a/test/elementhandle-misc.spec.ts +++ b/test/elementhandle-misc.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should hover', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/scrollable.html'); diff --git a/test/elementhandle-owner-frame.spec.ts b/test/elementhandle-owner-frame.spec.ts index 958fbe771c..a4986230a0 100644 --- a/test/elementhandle-owner-frame.spec.ts +++ b/test/elementhandle-owner-frame.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame } from './utils'; it('should work', async ({ page, server }) => { diff --git a/test/elementhandle-press.spec.ts b/test/elementhandle-press.spec.ts index b10228f043..e85558d459 100644 --- a/test/elementhandle-press.spec.ts +++ b/test/elementhandle-press.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({ page }) => { await page.setContent(``); diff --git a/test/elementhandle-query-selector.spec.ts b/test/elementhandle-query-selector.spec.ts index 563f5e3a57..bf64349abf 100644 --- a/test/elementhandle-query-selector.spec.ts +++ b/test/elementhandle-query-selector.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should query existing element', async ({page, server}) => { await page.goto(server.PREFIX + '/playground.html'); diff --git a/test/elementhandle-screenshot.spec.ts b/test/elementhandle-screenshot.spec.ts index 6bf74100d2..6ca1bdbbb7 100644 --- a/test/elementhandle-screenshot.spec.ts +++ b/test/elementhandle-screenshot.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; import { verifyViewport } from './utils'; import {PNG} from 'pngjs'; diff --git a/test/elementhandle-scroll-into-view.spec.ts b/test/elementhandle-scroll-into-view.spec.ts index 1d43bf97e2..b354f6c2fd 100644 --- a/test/elementhandle-scroll-into-view.spec.ts +++ b/test/elementhandle-scroll-into-view.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({ page, server }) => { await page.goto(server.PREFIX + '/offscreenbuttons.html'); diff --git a/test/elementhandle-select-text.spec.ts b/test/elementhandle-select-text.spec.ts index ea86b89bb7..c750e1d039 100644 --- a/test/elementhandle-select-text.spec.ts +++ b/test/elementhandle-select-text.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should select textarea', async ({ page, server, isFirefox }) => { await page.goto(server.PREFIX + '/input/textarea.html'); diff --git a/test/elementhandle-type.spec.ts b/test/elementhandle-type.spec.ts index 02fae2f1d0..cd0ffabc12 100644 --- a/test/elementhandle-type.spec.ts +++ b/test/elementhandle-type.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({ page }) => { await page.setContent(``); diff --git a/test/elementhandle-wait-for-element-state.spec.ts b/test/elementhandle-wait-for-element-state.spec.ts index d7259e6201..b7a2da0165 100644 --- a/test/elementhandle-wait-for-element-state.spec.ts +++ b/test/elementhandle-wait-for-element-state.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; async function giveItAChanceToResolve(page) { for (let i = 0; i < 5; i++) diff --git a/test/emulation-focus.spec.ts b/test/emulation-focus.spec.ts index f59c7331aa..1398326bf3 100644 --- a/test/emulation-focus.spec.ts +++ b/test/emulation-focus.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame } from './utils'; it('should think that it is focused by default', async ({page}) => { diff --git a/test/eval-on-selector-all.spec.ts b/test/eval-on-selector-all.spec.ts index 486365765f..24f4e1bc21 100644 --- a/test/eval-on-selector-all.spec.ts +++ b/test/eval-on-selector-all.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work with css selector', async ({page, server}) => { await page.setContent('
hello
beautiful
world!
'); diff --git a/test/eval-on-selector.spec.ts b/test/eval-on-selector.spec.ts index 43715f9941..cfaf725d25 100644 --- a/test/eval-on-selector.spec.ts +++ b/test/eval-on-selector.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work with css selector', async ({page, server}) => { await page.setContent('
43543
'); diff --git a/test/firefox/launcher.spec.ts b/test/firefox/launcher.spec.ts index 18492eb035..e0744ff512 100644 --- a/test/firefox/launcher.spec.ts +++ b/test/firefox/launcher.spec.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { it, expect, options } from '../playwright.fixtures'; +import { it, expect, options } from '../fixtures'; it('should pass firefox user preferences', (test, parameters) => { test.skip(!options.FIREFOX(parameters)); diff --git a/test/fixtures.spec.ts b/test/fixtures.spec.ts index 7a058fa054..8043a9b986 100644 --- a/test/fixtures.spec.ts +++ b/test/fixtures.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { options } from './playwright.fixtures'; +import { options } from './fixtures'; import { serverFixtures } from './remoteServer.fixture'; import { execSync } from 'child_process'; import path from 'path'; diff --git a/test/fixtures.ts b/test/fixtures.ts new file mode 100644 index 0000000000..cdff300b24 --- /dev/null +++ b/test/fixtures.ts @@ -0,0 +1,170 @@ +/** + * 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. + */ + +import { config } from '@playwright/test-runner'; +import assert from 'assert'; +import childProcess from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import util from 'util'; +import type { Browser, BrowserContext, BrowserType, Page } from '../index'; +import { Connection } from '../lib/client/connection'; +import { Transport } from '../lib/protocol/transport'; +import { installCoverageHooks } from './coverage'; +import { fixtures as httpFixtures } from './http.fixtures'; +import { fixtures as implFixtures } from './impl.fixtures'; +import { fixtures as platformFixtures, options as platformOptions } from './platform.fixtures'; +import { fixtures as playwrightFixtures, options as playwrightOptions } from './playwright.fixtures'; +export { expect } from '@playwright/test/out/matcher.fixtures'; +export { config } from '@playwright/test-runner'; + +const removeFolderAsync = util.promisify(require('rimraf')); + +type AllParameters = { + browserName: string; +}; + +type AllWorkerFixtures = { + golden: (path: string) => string; +}; + +type AllTestFixtures = { + createUserDataDir: () => Promise; + launchPersistent: (options?: Parameters['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>; +}; + +export const fixtures = playwrightFixtures + .union(httpFixtures) + .union(platformFixtures) + .union(implFixtures) + .declareParameters() + .declareWorkerFixtures() + .declareTestFixtures(); +const { defineTestFixture, defineWorkerFixture, overrideWorkerFixture } = fixtures; + +export const it = fixtures.it; +export const fit = fixtures.fit; +export const xit = fixtures.xit; +export const describe = fixtures.describe; +export const fdescribe = fixtures.fdescribe; +export const xdescribe = fixtures.xdescribe; +export const beforeEach = fixtures.beforeEach; +export const afterEach = fixtures.afterEach; +export const beforeAll = fixtures.beforeAll; +export const afterAll = fixtures.afterAll; + +export const options = { + ...platformOptions, + ...playwrightOptions, + WIRE: !!process.env.PWWIRE, +}; + +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; +}; + +overrideWorkerFixture('defaultBrowserOptions', async ({browserName}, runTest) => { + const executablePath = getExecutablePath(browserName); + if (executablePath) + console.error(`Using executable at ${executablePath}`); + await runTest({ + handleSIGINT: false, + slowMo: options.SLOW_MO, + headless: options.HEADLESS, + executablePath, + artifactsPath: config.outputDir, + }); +}); + +overrideWorkerFixture('playwright', async ({browserName, testWorkerIndex, platform}, test) => { + assert(platform); // Depend on platform to generate all tests. + const {coverage, uninstall} = installCoverageHooks(browserName); + if (options.WIRE) { + require('../lib/utils/utils').setUnderTest(); + const connection = new Connection(); + const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server.js'), [], { + 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 test(playwrightObject); + spawnedProcess.removeListener('exit', onExit); + spawnedProcess.stdin.destroy(); + spawnedProcess.stdout.destroy(); + spawnedProcess.stderr.destroy(); + await teardownCoverage(); + } else { + const playwright = require('../index'); + await test(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'); + } +}); + +defineWorkerFixture('golden', async ({browserName}, test) => { + await test(p => path.join(browserName, p)); +}); + +defineTestFixture('createUserDataDir', async ({testOutputDir}, runTest) => { + let counter = 0; + const dirs: string[] = []; + async function createUserDataDir() { + const dir = path.join(testOutputDir, `user-data-dir-${counter++}`); + dirs.push(dir); + await fs.promises.mkdir(dir, { recursive: true }); + return dir; + } + await runTest(createUserDataDir); + // Remove user data dirs, because we cannot upload them as test result artifacts. + // - Firefox removes lock file later, repsumably from another watchdog process? + // - WebKit has circular symlinks that makes CI go crazy. + await Promise.all(dirs.map(dir => removeFolderAsync(dir).catch(e => {}))); +}); + +defineTestFixture('launchPersistent', async ({createUserDataDir, defaultBrowserOptions, browserType}, test) => { + let context; + async function launchPersistent(options) { + if (context) + throw new Error('can only launch one persitent context'); + const userDataDir = await createUserDataDir(); + context = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, ...options}); + const page = context.pages()[0]; + return {context, page}; + } + await test(launchPersistent); + if (context) + await context.close(); +}); diff --git a/test/focus.spec.ts b/test/focus.spec.ts index 5d8a232c58..26f920f02f 100644 --- a/test/focus.spec.ts +++ b/test/focus.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should work', (test, parameters) => { test.skip(options.FIREFOX(parameters)); diff --git a/test/frame-evaluate.spec.ts b/test/frame-evaluate.spec.ts index 6c2a40ae6f..584e4772e6 100644 --- a/test/frame-evaluate.spec.ts +++ b/test/frame-evaluate.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame, detachFrame } from './utils'; import type { Frame } from '../src/client/frame'; diff --git a/test/frame-frame-element.spec.ts b/test/frame-frame-element.spec.ts index cd8f5dd64d..033c1e8a10 100644 --- a/test/frame-frame-element.spec.ts +++ b/test/frame-frame-element.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should work', async ({page, server}) => { diff --git a/test/frame-goto.spec.ts b/test/frame-goto.spec.ts index 8b91b3338b..7ff31ca203 100644 --- a/test/frame-goto.spec.ts +++ b/test/frame-goto.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should navigate subframes', async ({page, server}) => { diff --git a/test/frame-hierarchy.spec.ts b/test/frame-hierarchy.spec.ts index 06c7dc3300..bdb7b87751 100644 --- a/test/frame-hierarchy.spec.ts +++ b/test/frame-hierarchy.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame, detachFrame } from './utils'; import type { Frame } from '../index'; diff --git a/test/geolocation.spec.ts b/test/geolocation.spec.ts index 3e00f4173e..13f6c92362 100644 --- a/test/geolocation.spec.ts +++ b/test/geolocation.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server, context}) => { await context.grantPermissions(['geolocation']); diff --git a/test/headful.spec.ts b/test/headful.spec.ts index b8b06ac05b..fdcf91b7c4 100644 --- a/test/headful.spec.ts +++ b/test/headful.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should have default url when launching browser', async ({browserType, defaultBrowserOptions, createUserDataDir}) => { const browserContext = await browserType.launchPersistentContext(await createUserDataDir(), {...defaultBrowserOptions, headless: false }); diff --git a/test/ignorehttpserrors.spec.ts b/test/ignorehttpserrors.spec.ts index 6c99b0a4d9..f4c083f59f 100644 --- a/test/ignorehttpserrors.spec.ts +++ b/test/ignorehttpserrors.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({browser, httpsServer}) => { let error = null; diff --git a/test/impl.fixtures.ts b/test/impl.fixtures.ts index d413cdc304..8aed0696da 100644 --- a/test/impl.fixtures.ts +++ b/test/impl.fixtures.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { fixtures as playwrightFixtures } from './upstream.fixtures'; +import { fixtures as playwrightFixtures } from './playwright.fixtures'; type ImplWorkerFixtures = { toImpl: (rpcObject: any) => any; diff --git a/test/interception.spec.ts b/test/interception.spec.ts index f8a61a3093..0a8ac6e462 100644 --- a/test/interception.spec.ts +++ b/test/interception.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { globToRegex } from '../lib/client/clientHelper'; import vm from 'vm'; diff --git a/test/jshandle-as-element.spec.ts b/test/jshandle-as-element.spec.ts index 557ae2dffd..d86e6d65af 100644 --- a/test/jshandle-as-element.spec.ts +++ b/test/jshandle-as-element.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page}) => { const aHandle = await page.evaluateHandle(() => document.body); diff --git a/test/jshandle-evaluate.spec.ts b/test/jshandle-evaluate.spec.ts index 0678d8382c..d820b4dc77 100644 --- a/test/jshandle-evaluate.spec.ts +++ b/test/jshandle-evaluate.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work with function', async ({page}) => { const windowHandle = await page.evaluateHandle(() => { diff --git a/test/jshandle-json-value.spec.ts b/test/jshandle-json-value.spec.ts index 38e62a17a2..09e9f8a2f2 100644 --- a/test/jshandle-json-value.spec.ts +++ b/test/jshandle-json-value.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page}) => { const aHandle = await page.evaluateHandle(() => ({foo: 'bar'})); diff --git a/test/jshandle-properties.spec.ts b/test/jshandle-properties.spec.ts index dfb6230398..53ffdbce28 100644 --- a/test/jshandle-properties.spec.ts +++ b/test/jshandle-properties.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page}) => { const aHandle = await page.evaluateHandle(() => ({ diff --git a/test/jshandle-to-string.spec.ts b/test/jshandle-to-string.spec.ts index c8340be2b6..2f5b1027d8 100644 --- a/test/jshandle-to-string.spec.ts +++ b/test/jshandle-to-string.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work for primitives', async ({page}) => { const numberHandle = await page.evaluateHandle(() => 2); diff --git a/test/keyboard.spec.ts b/test/keyboard.spec.ts index 5abce1a867..d8209302bd 100644 --- a/test/keyboard.spec.ts +++ b/test/keyboard.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame } from './utils'; it('should type into a textarea', async ({page}) => { diff --git a/test/launcher.spec.ts b/test/launcher.spec.ts index 115255afe1..fc6fcbad53 100644 --- a/test/launcher.spec.ts +++ b/test/launcher.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should require top-level Errors', async ({}) => { const Errors = require('../lib/utils/errors.js'); diff --git a/test/logger.spec.ts b/test/logger.spec.ts index 84fb1712a7..4e7b4dd235 100644 --- a/test/logger.spec.ts +++ b/test/logger.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should log', async ({browserType, defaultBrowserOptions}) => { const log = []; diff --git a/test/mouse.spec.ts b/test/mouse.spec.ts index a221f58b41..c0dd442825 100644 --- a/test/mouse.spec.ts +++ b/test/mouse.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, xdescribe, options } from './playwright.fixtures'; +import { it, expect, xdescribe, options } from './fixtures'; function dimensions() { const rect = document.querySelector('textarea').getBoundingClientRect(); diff --git a/test/navigation.spec.ts b/test/navigation.spec.ts index f92cf82cf3..4f6218e3a9 100644 --- a/test/navigation.spec.ts +++ b/test/navigation.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it } from './playwright.fixtures'; +import { it } from './fixtures'; it('should work with _blank target', async ({page, server}) => { server.setRoute('/empty.html', (req, res) => { diff --git a/test/network-request.spec.ts b/test/network-request.spec.ts index 4f4b229311..ac6adb9f6f 100644 --- a/test/network-request.spec.ts +++ b/test/network-request.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import { attachFrame } from './utils'; it('should work for main frame navigation request', async ({page, server}) => { diff --git a/test/network-response.spec.ts b/test/network-response.spec.ts index e03cd4ef07..60b04e6dd7 100644 --- a/test/network-response.spec.ts +++ b/test/network-response.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import fs from 'fs'; import path from 'path'; diff --git a/test/page-add-init-script.spec.ts b/test/page-add-init-script.spec.ts index c3855c4eec..ffb2296cab 100644 --- a/test/page-add-init-script.spec.ts +++ b/test/page-add-init-script.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import path from 'path'; it('should evaluate before anything else on the page', async ({ page, server }) => { diff --git a/test/page-add-script-tag.spec.ts b/test/page-add-script-tag.spec.ts index 5f170d126a..d18211e670 100644 --- a/test/page-add-script-tag.spec.ts +++ b/test/page-add-script-tag.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import path from 'path'; it('should throw an error if no options are provided', async ({page, server}) => { diff --git a/test/page-add-style-tag.spec.ts b/test/page-add-style-tag.spec.ts index 7887cf9c60..03c1ad6954 100644 --- a/test/page-add-style-tag.spec.ts +++ b/test/page-add-style-tag.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import path from 'path'; it('should throw an error if no options are provided', async ({page, server}) => { diff --git a/test/page-basic.spec.ts b/test/page-basic.spec.ts index d82db241d3..567021afd9 100644 --- a/test/page-basic.spec.ts +++ b/test/page-basic.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should reject all promises when page is closed', async ({context}) => { const newPage = await context.newPage(); diff --git a/test/page-emulate-media.spec.ts b/test/page-emulate-media.spec.ts index 2f6d0b05f1..3a1ad62608 100644 --- a/test/page-emulate-media.spec.ts +++ b/test/page-emulate-media.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should emulate type', async ({page, server}) => { diff --git a/test/page-evaluate-handle.spec.ts b/test/page-evaluate-handle.spec.ts index 0f6f81315d..13e0d7a11a 100644 --- a/test/page-evaluate-handle.spec.ts +++ b/test/page-evaluate-handle.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server}) => { const windowHandle = await page.evaluateHandle(() => window); diff --git a/test/page-evaluate.spec.ts b/test/page-evaluate.spec.ts index 89d84b6ade..a6414401f8 100644 --- a/test/page-evaluate.spec.ts +++ b/test/page-evaluate.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should work', async ({ page, server }) => { const result = await page.evaluate(() => 7 * 3); diff --git a/test/page-event-console.spec.ts b/test/page-event-console.spec.ts index d0238e7a3a..e9c174fff6 100644 --- a/test/page-event-console.spec.ts +++ b/test/page-event-console.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import util from 'util'; it('should work', async ({page, server}) => { diff --git a/test/page-event-crash.spec.ts b/test/page-event-crash.spec.ts index bb41b8b297..7e20b3c06b 100644 --- a/test/page-event-crash.spec.ts +++ b/test/page-event-crash.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; function crash(page, toImpl, browserName) { if (browserName === 'chromium') diff --git a/test/page-event-network.spec.ts b/test/page-event-network.spec.ts index 9aad1658f9..6b20a8bb4d 100644 --- a/test/page-event-network.spec.ts +++ b/test/page-event-network.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('Page.Events.Request', async ({page, server}) => { const requests = []; diff --git a/test/page-event-pageerror.spec.ts b/test/page-event-pageerror.spec.ts index 112b781d8b..134d498088 100644 --- a/test/page-event-pageerror.spec.ts +++ b/test/page-event-pageerror.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; it('should fire', async ({page, server, isWebKit}) => { const [error] = await Promise.all([ diff --git a/test/page-event-popup.spec.ts b/test/page-event-popup.spec.ts index 6d45d2b800..a07607fb7e 100644 --- a/test/page-event-popup.spec.ts +++ b/test/page-event-popup.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({browser}) => { const context = await browser.newContext(); diff --git a/test/page-event-request.spec.ts b/test/page-event-request.spec.ts index 6948d5d182..86ce6b2a52 100644 --- a/test/page-event-request.spec.ts +++ b/test/page-event-request.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame } from './utils'; it('should fire for navigation requests', async ({page, server}) => { diff --git a/test/page-expose-function.spec.ts b/test/page-expose-function.spec.ts index 9e08cd61b9..82eaf56fe4 100644 --- a/test/page-expose-function.spec.ts +++ b/test/page-expose-function.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('exposeBinding should work', async ({browser}) => { const context = await browser.newContext(); diff --git a/test/page-fill.spec.ts b/test/page-fill.spec.ts index c873d75123..3909461637 100644 --- a/test/page-fill.spec.ts +++ b/test/page-fill.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; async function giveItAChanceToFill(page) { for (let i = 0; i < 5; i++) diff --git a/test/page-goto.spec.ts b/test/page-goto.spec.ts index 78253f743e..78463b605e 100644 --- a/test/page-goto.spec.ts +++ b/test/page-goto.spec.ts @@ -17,7 +17,7 @@ import path from 'path'; import url from 'url'; -import { expect, it, options } from './playwright.fixtures'; +import { expect, it, options } from './fixtures'; import { expectedSSLError } from './utils'; it('should work', async ({page, server}) => { diff --git a/test/page-history.spec.ts b/test/page-history.spec.ts index db4ee444f4..e121af11f7 100644 --- a/test/page-history.spec.ts +++ b/test/page-history.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import url from 'url'; it('page.goBack should work', async ({page, server}) => { diff --git a/test/page-network-idle.spec.ts b/test/page-network-idle.spec.ts index a54bd56949..6904c4890a 100644 --- a/test/page-network-idle.spec.ts +++ b/test/page-network-idle.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import type { Frame, Page } from '..'; import { TestServer } from '../utils/testserver'; diff --git a/test/page-route.spec.ts b/test/page-route.spec.ts index 63898a1143..0c281fc50b 100644 --- a/test/page-route.spec.ts +++ b/test/page-route.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should intercept', async ({page, server}) => { let intercepted = false; diff --git a/test/page-screenshot.spec.ts b/test/page-screenshot.spec.ts index 29d33d8dd1..c0d6089b5d 100644 --- a/test/page-screenshot.spec.ts +++ b/test/page-screenshot.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; import { verifyViewport } from './utils'; import path from 'path'; import fs from 'fs'; diff --git a/test/page-select-option.spec.ts b/test/page-select-option.spec.ts index 70fe47976e..ecd7365d6d 100644 --- a/test/page-select-option.spec.ts +++ b/test/page-select-option.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should select single option', async ({page, server}) => { await page.goto(server.PREFIX + '/input/select.html'); diff --git a/test/page-set-content.spec.ts b/test/page-set-content.spec.ts index 2e107e86b3..e658771337 100644 --- a/test/page-set-content.spec.ts +++ b/test/page-set-content.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; const expectedOutput = '
hello
'; diff --git a/test/page-set-extra-http-headers.spec.ts b/test/page-set-extra-http-headers.spec.ts index 71013c4c24..2244fe7f6a 100644 --- a/test/page-set-extra-http-headers.spec.ts +++ b/test/page-set-extra-http-headers.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server}) => { await page.setExtraHTTPHeaders({ diff --git a/test/page-set-input-files.spec.ts b/test/page-set-input-files.spec.ts index a81b064c8d..d41e8dc6e3 100644 --- a/test/page-set-input-files.spec.ts +++ b/test/page-set-input-files.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import path from 'path'; import fs from 'fs'; diff --git a/test/page-wait-for-load-state.spec.ts b/test/page-wait-for-load-state.spec.ts index a7769c4b5c..10fb28fa92 100644 --- a/test/page-wait-for-load-state.spec.ts +++ b/test/page-wait-for-load-state.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import type { Route } from '..'; it('should pick up ongoing navigation', async ({page, server}) => { diff --git a/test/page-wait-for-navigation.spec.ts b/test/page-wait-for-navigation.spec.ts index dd9e89f47e..d02e59f926 100644 --- a/test/page-wait-for-navigation.spec.ts +++ b/test/page-wait-for-navigation.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import type { Frame } from '../index'; import { expectedSSLError } from './utils'; diff --git a/test/page-wait-for-request.spec.ts b/test/page-wait-for-request.spec.ts index b7d5916c11..a0e8d7003f 100644 --- a/test/page-wait-for-request.spec.ts +++ b/test/page-wait-for-request.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import vm from 'vm'; diff --git a/test/page-wait-for-response.spec.ts b/test/page-wait-for-response.spec.ts index e209d71618..96eb7e06db 100644 --- a/test/page-wait-for-response.spec.ts +++ b/test/page-wait-for-response.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server}) => { await page.goto(server.EMPTY_PAGE); diff --git a/test/pdf.spec.ts b/test/pdf.spec.ts index fc267084c9..cdd64157b5 100644 --- a/test/pdf.spec.ts +++ b/test/pdf.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import fs from 'fs'; import path from 'path'; diff --git a/test/permissions.spec.ts b/test/permissions.spec.ts index 3cd4bd5ab5..dfc04ff897 100644 --- a/test/permissions.spec.ts +++ b/test/permissions.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; function getPermission(page, name) { return page.evaluate(name => navigator.permissions.query({name}).then(result => result.state), name); diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.ts index fca655d455..a927915973 100644 --- a/test/playwright.fixtures.ts +++ b/test/playwright.fixtures.ts @@ -14,160 +14,140 @@ * limitations under the License. */ -import { config } from '@playwright/test-runner'; -import assert from 'assert'; -import childProcess from 'child_process'; +import { config, fixtures as baseFixtures } from '@playwright/test-runner'; import fs from 'fs'; +import os from 'os'; import path from 'path'; import util from 'util'; -import type { Browser, BrowserContext, BrowserType, Page } from '../index'; -import { Connection } from '../lib/client/connection'; -import { Transport } from '../lib/protocol/transport'; -import { installCoverageHooks } from './coverage'; -import { fixtures as httpFixtures } from './http.fixtures'; -import { fixtures as implFixtures } from './impl.fixtures'; -import { fixtures as platformFixtures, options as platformOptions } from './platform.fixtures'; -import { fixtures as playwrightFixtures, options as playwrightOptions, PlaywrightParameters } from './upstream.fixtures'; -export { expect } from '@playwright/test/out/matcher.fixtures'; -export { config } from '@playwright/test-runner'; +import type { Browser, BrowserContext, BrowserContextOptions, BrowserType, LaunchOptions, Page } from '../index'; +const mkdtempAsync = util.promisify(fs.mkdtemp); const removeFolderAsync = util.promisify(require('rimraf')); -type AllParameters = { +type PlaywrightParameters = { browserName: string; }; -type AllWorkerFixtures = { - golden: (path: string) => string; +type PlaywrightWorkerFixtures = { + defaultBrowserOptions: LaunchOptions; + playwright: typeof import('../index'); + browserType: BrowserType; + browser: Browser; + isChromium: boolean; + isFirefox: boolean; + isWebKit: boolean; }; -type AllTestFixtures = { - createUserDataDir: () => Promise; - launchPersistent: (options?: Parameters['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>; +type PlaywrightTestFixtures = { + context: BrowserContext; + page: Page; + testOutputDir: string; + tmpDir: string; }; -export const fixtures = playwrightFixtures - .union(httpFixtures) - .union(platformFixtures) - .union(implFixtures) - .declareParameters() - .declareWorkerFixtures() - .declareTestFixtures(); -const { defineTestFixture, defineWorkerFixture, overrideWorkerFixture } = fixtures; +export const fixtures = baseFixtures + .declareParameters() + .declareWorkerFixtures() + .declareTestFixtures(); -export const it = fixtures.it; -export const fit = fixtures.fit; -export const xit = fixtures.xit; -export const describe = fixtures.describe; -export const fdescribe = fixtures.fdescribe; -export const xdescribe = fixtures.xdescribe; -export const beforeEach = fixtures.beforeEach; -export const afterEach = fixtures.afterEach; -export const beforeAll = fixtures.beforeAll; -export const afterAll = fixtures.afterAll; +const { defineTestFixture, defineWorkerFixture, defineParameter, generateParametrizedTests } = fixtures; export const options = { - ...platformOptions, - ...playwrightOptions, CHROMIUM: (parameters: PlaywrightParameters) => parameters.browserName === 'chromium', FIREFOX: (parameters: PlaywrightParameters) => parameters.browserName === 'firefox', WEBKIT: (parameters: PlaywrightParameters) => parameters.browserName === 'webkit', - WIRE: !!process.env.PWWIRE, + HEADLESS: !!valueFromEnv('HEADLESS', true), + SLOW_MO: valueFromEnv('SLOW_MO', 0), + TRACING: valueFromEnv('TRACING', false), }; -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; -}; - -overrideWorkerFixture('defaultBrowserOptions', async ({browserName}, runTest) => { - const executablePath = getExecutablePath(browserName); - if (executablePath) - console.error(`Using executable at ${executablePath}`); +defineWorkerFixture('defaultBrowserOptions', async ({}, runTest) => { await runTest({ handleSIGINT: false, slowMo: options.SLOW_MO, headless: options.HEADLESS, - executablePath, artifactsPath: config.outputDir, }); }); -overrideWorkerFixture('playwright', async ({browserName, testWorkerIndex, platform}, test) => { - assert(platform); // Depend on platform to generate all tests. - const {coverage, uninstall} = installCoverageHooks(browserName); - if (options.WIRE) { - require('../lib/utils/utils').setUnderTest(); - const connection = new Connection(); - const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server.js'), [], { - 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 test(playwrightObject); - spawnedProcess.removeListener('exit', onExit); - spawnedProcess.stdin.destroy(); - spawnedProcess.stdout.destroy(); - spawnedProcess.stderr.destroy(); - await teardownCoverage(); - } else { - const playwright = require('../index'); - await test(playwright); - await teardownCoverage(); - } +defineWorkerFixture('playwright', async ({}, test) => { + const playwright = require('../index'); + await test(playwright); +}); - 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'); +defineWorkerFixture('browserType', async ({playwright, browserName}, test) => { + const browserType = playwright[browserName]; + await test(browserType); +}); + +defineParameter('browserName', 'Browser type name', ''); + +generateParametrizedTests( + 'browserName', + process.env.BROWSER ? [process.env.BROWSER] : ['chromium', 'webkit', 'firefox']); + +defineWorkerFixture('isChromium', async ({browserName}, test) => { + await test(browserName === 'chromium'); +}); + +defineWorkerFixture('isFirefox', async ({browserName}, test) => { + await test(browserName === 'firefox'); +}); + +defineWorkerFixture('isWebKit', async ({browserName}, test) => { + await test(browserName === 'webkit'); +}); + +defineWorkerFixture('browser', async ({browserType, defaultBrowserOptions}, test) => { + const browser = await browserType.launch(defaultBrowserOptions); + await test(browser); + if (browser.contexts().length !== 0) { + console.warn(`\nWARNING: test did not close all created contexts! ${new Error().stack}\n`); + await Promise.all(browser.contexts().map(context => context.close())).catch(e => void 0); + } + await browser.close(); +}); + +defineTestFixture('testOutputDir', async ({ testInfo }, runTest) => { + const relativePath = path.relative(config.testDir, testInfo.file).replace(/\.spec\.[jt]s/, ''); + const sanitizedTitle = testInfo.title.replace(/[^\w\d]+/g, '_'); + const testOutputDir = path.join(config.outputDir, relativePath, sanitizedTitle); + await fs.promises.mkdir(testOutputDir, { recursive: true }); + await runTest(testOutputDir); + const files = await fs.promises.readdir(testOutputDir); + if (!files.length) { + // Do not leave an empty useless directory. + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 + await removeFolderAsync(testOutputDir).catch(e => {}); } }); -defineWorkerFixture('golden', async ({browserName}, test) => { - await test(p => path.join(browserName, p)); +defineTestFixture('context', async ({ browser, testOutputDir }, runTest) => { + const contextOptions: BrowserContextOptions = { + relativeArtifactsPath: path.relative(config.outputDir, testOutputDir), + recordTrace: !!options.TRACING, + recordVideos: !!options.TRACING, + }; + const context = await browser.newContext(contextOptions); + await runTest(context); + await context.close(); }); -defineTestFixture('createUserDataDir', async ({testOutputDir}, runTest) => { - let counter = 0; - const dirs: string[] = []; - async function createUserDataDir() { - const dir = path.join(testOutputDir, `user-data-dir-${counter++}`); - dirs.push(dir); - await fs.promises.mkdir(dir, { recursive: true }); - return dir; - } - await runTest(createUserDataDir); - // Remove user data dirs, because we cannot upload them as test result artifacts. - // - Firefox removes lock file later, repsumably from another watchdog process? - // - WebKit has circular symlinks that makes CI go crazy. - await Promise.all(dirs.map(dir => removeFolderAsync(dir).catch(e => {}))); +defineTestFixture('page', async ({ context, testOutputDir, testInfo }, runTest) => { + const page = await context.newPage(); + await runTest(page); + if (testInfo.status === 'failed' || testInfo.status === 'timedOut') + await page.screenshot({ timeout: 5000, path: path.join(testOutputDir, 'test-failed.png') }); }); -defineTestFixture('launchPersistent', async ({createUserDataDir, defaultBrowserOptions, browserType}, test) => { - let context; - async function launchPersistent(options) { - if (context) - throw new Error('can only launch one persitent context'); - const userDataDir = await createUserDataDir(); - context = await browserType.launchPersistentContext(userDataDir, {...defaultBrowserOptions, ...options}); - const page = context.pages()[0]; - return {context, page}; - } - await test(launchPersistent); - if (context) - await context.close(); +defineTestFixture('tmpDir', async ({}, test) => { + const tmpDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright-test-')); + await test(tmpDir); + await removeFolderAsync(tmpDir).catch(e => {}); }); + +function valueFromEnv(name, defaultValue) { + if (!(name in process.env)) + return defaultValue; + return JSON.parse(process.env[name]); +} diff --git a/test/popup.spec.ts b/test/popup.spec.ts index 5b44143df1..e647b843b6 100644 --- a/test/popup.spec.ts +++ b/test/popup.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should inherit user agent from browser context', async function({browser, server}) { const context = await browser.newContext({ diff --git a/test/proxy.spec.ts b/test/proxy.spec.ts index a7645f2d95..826498d946 100644 --- a/test/proxy.spec.ts +++ b/test/proxy.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import socks from 'socksv5'; diff --git a/test/queryselector.spec.ts b/test/queryselector.spec.ts index f34f351ab4..a5fb19035c 100644 --- a/test/queryselector.spec.ts +++ b/test/queryselector.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should throw for non-string selector', async ({page}) => { const error = await page.$(null).catch(e => e); diff --git a/test/remoteServer.fixture.ts b/test/remoteServer.fixture.ts index 703ee5ce19..9d3b7337ab 100644 --- a/test/remoteServer.fixture.ts +++ b/test/remoteServer.fixture.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { fixtures as baseFixtures } from './playwright.fixtures'; +import { fixtures as baseFixtures } from './fixtures'; import path from 'path'; import { spawn } from 'child_process'; diff --git a/test/request-continue.spec.ts b/test/request-continue.spec.ts index 22bc23714f..eeb2e9d37c 100644 --- a/test/request-continue.spec.ts +++ b/test/request-continue.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work', async ({page, server}) => { await page.route('**/*', route => route.continue()); diff --git a/test/request-fulfill.spec.ts b/test/request-fulfill.spec.ts index cc31e38ec3..ed363a7f29 100644 --- a/test/request-fulfill.spec.ts +++ b/test/request-fulfill.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect, options } from './playwright.fixtures'; +import { it, expect, options } from './fixtures'; import fs from 'fs'; import path from 'path'; diff --git a/test/screencast.spec.ts b/test/screencast.spec.ts index 872942aaee..1e890f4553 100644 --- a/test/screencast.spec.ts +++ b/test/screencast.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { options, fixtures as playwrightFixtures, config } from './playwright.fixtures'; +import { options, fixtures as playwrightFixtures, config } from './fixtures'; import type { Page, Browser } from '..'; import fs from 'fs'; diff --git a/test/selectors-css.spec.ts b/test/selectors-css.spec.ts index 7ef156c922..45f775d5fd 100644 --- a/test/selectors-css.spec.ts +++ b/test/selectors-css.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work for open shadow roots', async ({page, server}) => { await page.goto(server.PREFIX + '/deep-shadow.html'); diff --git a/test/selectors-misc.spec.ts b/test/selectors-misc.spec.ts index dc85816c13..6dd66d8418 100644 --- a/test/selectors-misc.spec.ts +++ b/test/selectors-misc.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should work for open shadow roots', async ({page, server}) => { await page.goto(server.PREFIX + '/deep-shadow.html'); diff --git a/test/selectors-register.spec.ts b/test/selectors-register.spec.ts index 5ab9ee7bee..098eb30e61 100644 --- a/test/selectors-register.spec.ts +++ b/test/selectors-register.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import path from 'path'; diff --git a/test/selectors-text.spec.ts b/test/selectors-text.spec.ts index 926970d95f..874b7ef2c3 100644 --- a/test/selectors-text.spec.ts +++ b/test/selectors-text.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('query', async ({page, isWebKit}) => { await page.setContent(`
yo
ya
\nye
`); diff --git a/test/slowmo.spec.ts b/test/slowmo.spec.ts index ceaeb92551..9ebaa4ece3 100644 --- a/test/slowmo.spec.ts +++ b/test/slowmo.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect, describe, options } from './playwright.fixtures'; +import { it, expect, describe, options } from './fixtures'; import { attachFrame } from './utils'; async function checkSlowMo(toImpl, page, task) { diff --git a/test/trace.spec.ts b/test/trace.spec.ts index 87ef38e057..78dcf2979f 100644 --- a/test/trace.spec.ts +++ b/test/trace.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import type * as trace from '../types/trace'; import * as path from 'path'; import * as fs from 'fs'; diff --git a/test/upstream.fixtures.ts b/test/upstream.fixtures.ts deleted file mode 100644 index 533abda24d..0000000000 --- a/test/upstream.fixtures.ts +++ /dev/null @@ -1,153 +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. - */ - -import { config, fixtures as baseFixtures } from '@playwright/test-runner'; -import fs from 'fs'; -import os from 'os'; -import path from 'path'; -import util from 'util'; -import type { Browser, BrowserContext, BrowserContextOptions, BrowserType, LaunchOptions, Page } from '../index'; - -const mkdtempAsync = util.promisify(fs.mkdtemp); -const removeFolderAsync = util.promisify(require('rimraf')); - -export type PlaywrightParameters = { - browserName: string; -}; - -type PlaywrightWorkerFixtures = { - defaultBrowserOptions: LaunchOptions; - playwright: typeof import('../index'); - browserType: BrowserType; - browser: Browser; - isChromium: boolean; - isFirefox: boolean; - isWebKit: boolean; -}; - -type PlaywrightTestFixtures = { - context: BrowserContext; - page: Page; - testOutputDir: string; - tmpDir: string; -}; - -export const fixtures = baseFixtures - .declareParameters() - .declareWorkerFixtures() - .declareTestFixtures(); - -const { defineTestFixture, defineWorkerFixture, defineParameter, generateParametrizedTests } = fixtures; - -export const options = { - CHROMIUM: (parameters: PlaywrightParameters) => parameters.browserName === 'chromium', - FIREFOX: (parameters: PlaywrightParameters) => parameters.browserName === 'firefox', - WEBKIT: (parameters: PlaywrightParameters) => parameters.browserName === 'webkit', - HEADLESS: !!valueFromEnv('HEADLESS', true), - SLOW_MO: valueFromEnv('SLOW_MO', 0), - TRACING: valueFromEnv('TRACING', false), -}; - -defineWorkerFixture('defaultBrowserOptions', async ({}, runTest) => { - await runTest({ - handleSIGINT: false, - slowMo: options.SLOW_MO, - headless: options.HEADLESS, - artifactsPath: config.outputDir, - }); -}); - -defineWorkerFixture('playwright', async ({}, test) => { - const playwright = require('../index'); - await test(playwright); -}); - -defineWorkerFixture('browserType', async ({playwright, browserName}, test) => { - const browserType = playwright[browserName]; - await test(browserType); -}); - -defineParameter('browserName', 'Browser type name', ''); - -generateParametrizedTests( - 'browserName', - process.env.BROWSER ? [process.env.BROWSER] : ['chromium', 'webkit', 'firefox']); - -defineWorkerFixture('isChromium', async ({browserName}, test) => { - await test(browserName === 'chromium'); -}); - -defineWorkerFixture('isFirefox', async ({browserName}, test) => { - await test(browserName === 'firefox'); -}); - -defineWorkerFixture('isWebKit', async ({browserName}, test) => { - await test(browserName === 'webkit'); -}); - -defineWorkerFixture('browser', async ({browserType, defaultBrowserOptions}, test) => { - const browser = await browserType.launch(defaultBrowserOptions); - await test(browser); - if (browser.contexts().length !== 0) { - console.warn(`\nWARNING: test did not close all created contexts! ${new Error().stack}\n`); - await Promise.all(browser.contexts().map(context => context.close())).catch(e => void 0); - } - await browser.close(); -}); - -defineTestFixture('testOutputDir', async ({ testInfo }, runTest) => { - const relativePath = path.relative(config.testDir, testInfo.file).replace(/\.spec\.[jt]s/, ''); - const sanitizedTitle = testInfo.title.replace(/[^\w\d]+/g, '_'); - const testOutputDir = path.join(config.outputDir, relativePath, sanitizedTitle); - await fs.promises.mkdir(testOutputDir, { recursive: true }); - await runTest(testOutputDir); - const files = await fs.promises.readdir(testOutputDir); - if (!files.length) { - // Do not leave an empty useless directory. - // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 - await removeFolderAsync(testOutputDir).catch(e => {}); - } -}); - -defineTestFixture('context', async ({ browser, testOutputDir }, runTest) => { - const contextOptions: BrowserContextOptions = { - relativeArtifactsPath: path.relative(config.outputDir, testOutputDir), - recordTrace: !!options.TRACING, - recordVideos: !!options.TRACING, - }; - const context = await browser.newContext(contextOptions); - await runTest(context); - await context.close(); -}); - -defineTestFixture('page', async ({ context, testOutputDir, testInfo }, runTest) => { - const page = await context.newPage(); - await runTest(page); - if (testInfo.status === 'failed' || testInfo.status === 'timedOut') - await page.screenshot({ timeout: 5000, path: path.join(testOutputDir, 'test-failed.png') }); -}); - -defineTestFixture('tmpDir', async ({}, test) => { - const tmpDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright-test-')); - await test(tmpDir); - await removeFolderAsync(tmpDir).catch(e => {}); -}); - -function valueFromEnv(name, defaultValue) { - if (!(name in process.env)) - return defaultValue; - return JSON.parse(process.env[name]); -} diff --git a/test/utils.ts b/test/utils.ts index 0bd8885fa7..a2e45f08c8 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { expect } from './playwright.fixtures'; +import { expect } from './fixtures'; import type { Frame, Page } from '../index'; export async function attachFrame(page: Page, frameId: string, url: string): Promise { diff --git a/test/wait-for-function.spec.ts b/test/wait-for-function.spec.ts index 2ec7961730..907b571646 100644 --- a/test/wait-for-function.spec.ts +++ b/test/wait-for-function.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; it('should timeout', async ({page}) => { const startTime = Date.now(); diff --git a/test/wait-for-selector-1.spec.ts b/test/wait-for-selector-1.spec.ts index 34ed18fde0..75cd859f7c 100644 --- a/test/wait-for-selector-1.spec.ts +++ b/test/wait-for-selector-1.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame, detachFrame } from './utils'; async function giveItTimeToLog(frame) { diff --git a/test/wait-for-selector-2.spec.ts b/test/wait-for-selector-2.spec.ts index d1477cfb43..b81addcb2b 100644 --- a/test/wait-for-selector-2.spec.ts +++ b/test/wait-for-selector-2.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import { attachFrame, detachFrame } from './utils'; const addElement = tag => document.body.appendChild(document.createElement(tag)); diff --git a/test/workers.spec.ts b/test/workers.spec.ts index 857b561795..c5c993d90b 100644 --- a/test/workers.spec.ts +++ b/test/workers.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { it, expect } from './playwright.fixtures'; +import { it, expect } from './fixtures'; import type { ConsoleMessage } from '..'; it('Page.workers', async function({page, server}) {