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
chore: remove GridClient, run only page tests in service mode (#13566)
Yury Semikhatskyaee6ba299ad7
diff --git a/.github/workflows/tests_secondary.yml b/.github/workflows/tests_secondary.ymlindex 4607cf4926..d5844b1ca3 100644--- a/.github/workflows/tests_secondary.yml+++ b/.github/workflows/tests_secondary.yml@@ -185,7 +185,12 @@ jobs:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1- run: npm run build- run: npx playwright install --with-deps chromium+ - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project='Chromium page tests'+ if: matrix.mode == 'service'+ env:+ PWTEST_MODE: ${{ matrix.mode }}- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run ctest+ if: matrix.mode != 'service'env:PWTEST_MODE: ${{ matrix.mode }}- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.jsondiff --git a/packages/playwright-core/src/grid/gridClient.ts b/packages/playwright-core/src/grid/gridClient.tsdeleted file mode 100644index 82966bdb7d..0000000000--- a/packages/playwright-core/src/grid/gridClient.ts+++ /dev/null@@ -1,60 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * 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 WebSocket from 'ws';-import { Connection } from '../client/connection';-import type { Playwright } from '../client/playwright';-import { getPlaywrightVersion } from '../common/userAgent';--export class GridClient {- private _ws: WebSocket;- private _playwright: Playwright;-- static async connect(gridURL: string) {- const params = new URLSearchParams();- params.set('pwVersion', getPlaywrightVersion(true /* majorMinorOnly */));- const ws = new WebSocket(`${gridURL}/claimWorker?` + params.toString());- const errorText = await Promise.race([- new Promise(f => ws.once('open', () => f(undefined))),- new Promise(f => ws.once('close', (code, reason) => f(reason))),- ]);- if (errorText)- throw errorText;- const connection = new Connection();- connection.markAsRemote();- connection.onmessage = (message: Object) => ws.send(JSON.stringify(message));- ws.on('message', message => connection.dispatch(JSON.parse(message.toString())));- ws.on('close', (code, reason) => connection.close(reason.toString()));- const playwright = await connection.initializePlaywright();- playwright._enablePortForwarding();- return new GridClient(ws, playwright);- }-- constructor(ws: WebSocket, playwright: Playwright) {- this._ws = ws;- this._playwright = playwright;- }-- playwright(): Playwright {- return this._playwright;- }-- close() {- this._ws.close();- }-}--diff --git a/packages/playwright-core/src/grid/gridServer.ts b/packages/playwright-core/src/grid/gridServer.tsindex 5757923962..2be67d84fd 100644--- a/packages/playwright-core/src/grid/gridServer.ts+++ b/packages/playwright-core/src/grid/gridServer.ts@@ -263,6 +263,7 @@ export class GridServer {// shouldHandle claims it accepts promise, except it doesn't.return true;}+ this._log('rejecting websocket request');return false;};diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.tsindex e65f37ac24..c03fab10e9 100644--- a/packages/playwright-test/src/cli.ts+++ b/packages/playwright-test/src/cli.ts@@ -242,7 +242,6 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {const { error } = await gridServer.createAgent();if (error)throw error;- process.env.PW_GRID = gridServer.gridURL();return async () => await gridServer.stop();}diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex ab5ff0ae47..758c9eabd6 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -21,7 +21,6 @@ import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorimport { rootTestType } from './testType';import { createGuid, debugMode } from 'playwright-core/lib/utils';import { removeFolders } from 'playwright-core/lib/utils/fileUtils';-import { GridClient } from 'playwright-core/lib/grid/gridClient';export { expect } from './expect';export const _baseTest: TestType<{}, {}> = rootTestType.test;import * as outOfProcess from 'playwright-core/lib/outofprocess';@@ -53,12 +52,8 @@ type WorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions & {export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({defaultBrowserType: [ 'chromium', { scope: 'worker', option: true } ],browserName: [ ({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: 'worker', option: true } ],- playwright: [async ({}, use, workerInfo) => {- if (process.env.PW_GRID) {- const gridClient = await GridClient.connect(process.env.PW_GRID);- await use(gridClient.playwright() as any);- gridClient.close();- } else if (process.env.PW_OUT_OF_PROCESS_DRIVER) {+ playwright: [async ({ }, use) => {+ if (process.env.PW_OUT_OF_PROCESS_DRIVER) {const impl = await outOfProcess.start({NODE_OPTIONS: undefined // Hide driver process while debugging.});diff --git a/tests/config/testMode.ts b/tests/config/testMode.tsindex cdc16c987d..1f5461b9eb 100644--- a/tests/config/testMode.ts+++ b/tests/config/testMode.ts@@ -14,7 +14,6 @@* limitations under the License.*/-import { GridClient } from '../../packages/playwright-core/lib/grid/gridClient';import { start } from '../../packages/playwright-core/lib/outofprocess';import type { Playwright } from '../../packages/playwright-core/lib/client/playwright';@@ -41,19 +40,6 @@ export class DriverTestMode implements TestMode {}}-export class ServiceTestMode implements TestMode {- private _gridClient: GridClient;-- async setup() {- this._gridClient = await GridClient.connect('ws://localhost:3333');- return this._gridClient.playwright();- }-- async teardown() {- this._gridClient.close();- }-}-export class DefaultTestMode implements TestMode {async setup() {return require('playwright-core');diff --git a/tests/config/testModeFixtures.ts b/tests/config/testModeFixtures.tsindex 077866d131..6e8561a0b1 100644--- a/tests/config/testModeFixtures.ts+++ b/tests/config/testModeFixtures.ts@@ -16,7 +16,7 @@import { test } from '@playwright/test';import type { TestModeName } from './testMode';-import { DefaultTestMode, DriverTestMode, ServiceTestMode } from './testMode';+import { DefaultTestMode, DriverTestMode } from './testMode';export type TestModeWorkerOptions = {mode: TestModeName;@@ -32,7 +32,7 @@ export const testModeTest = test.extend<{}, TestModeWorkerOptions & TestModeWorkplaywright: [ async ({ mode }, run) => {const testMode = {default: new DefaultTestMode(),- service: new ServiceTestMode(),+ service: new DefaultTestMode(),driver: new DriverTestMode(),service2: new DefaultTestMode(),}[mode];diff --git a/tests/library/playwright.config.ts b/tests/library/playwright.config.tsindex 8c80259938..f7d6d6e518 100644--- a/tests/library/playwright.config.ts+++ b/tests/library/playwright.config.ts@@ -69,13 +69,26 @@ const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & Playwrighif (mode === 'service') {config.webServer = {- command: 'npx playwright experimental-grid-server',+ command: 'npx playwright experimental-grid-server --auth-token=mysecret --address=http://localhost:3333 --port=3333',port: 3333,reuseExistingServer: true,env: {+ PWTEST_UNSAFE_GRID_VERSION: '1',PLAYWRIGHT_EXPERIMENTAL_FEATURES: '1',},};+ config.use.connectOptions = {+ wsEndpoint: 'ws://localhost:3333/mysecret/claimWorker?os=linux',+ };+ config.projects = [{+ name: 'Chromium page tests',+ testMatch: /page\/.*spec.ts$/,+ testIgnore: 'screenshot',+ use: {+ browserName: 'chromium',+ mode+ }+ }];}if (mode === 'service2') {diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.tsindex d1ec8a3611..cc1b07e1e8 100644--- a/tests/playwright-test/playwright-test-fixtures.ts+++ b/tests/playwright-test/playwright-test-fixtures.ts@@ -142,7 +142,6 @@ async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], b// END: Reserved CIPW_TEST_HTML_REPORT_OPEN: undefined,PLAYWRIGHT_DOCKER: undefined,- PW_GRID: undefined,PW_TEST_REPORTER: undefined,PW_TEST_REPORTER_WS_ENDPOINT: undefined,PW_TEST_SOURCE_TRANSFORM: undefined,