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
feat(test-runner): mark launch as experimental (#7757)
Joel Einbinder483b7d6a0d75
diff --git a/docs/src/test-advanced.md b/docs/src/test-advanced.mdindex 423925e4b6..8d536ec6fd 100644--- a/docs/src/test-advanced.md+++ b/docs/src/test-advanced.md@@ -42,7 +42,6 @@ These options would be typically different between local development and CI oper- `reportSlowTests: { max: number, threshold: number } | null` - Whether to report slow tests. When `null`, slow tests are not reported. Otherwise, tests that took more than `threshold` milliseconds are reported as slow, but no more than `max` number of them. Passing zero as `max` reports all slow tests that exceed the threshold.- `shard: { total: number, current: number } | null` - [Shard](./test-parallel.md#shards) information.- `updateSnapshots: boolean` - Whether to update expected snapshots with the actual results produced by the test run.-- `launch: { command: string, waitForPort?: number, waitForPortTimeout?: number, strict?: boolean, cwd?: string, env?: object }[]` - Launch a process before the tests will start. When using `waitForPort` it will wait until the server is available, see [launch server](#launching-a-development-web-server-during-the-tests) configuration for examples. `strict` will verify that the `waitForPort` port is available instead of using it by default.- `workers: number` - The maximum number of concurrent worker processes to use for parallelizing tests.Note that each [test project](#projects) can provide its own test suite options, for example two projects can run different tests by providing different `testDir`s. However, test run options are shared between all projects.@@ -201,80 +200,6 @@ export const test = base.extend<{ saveLogs: void }>({});```-## Launching a development web server during the tests--To launch a server during the tests, use the `launch` option in the [configuration file](#configuration-object).--You can specify a port via `waitForPort` or additional environment variables, see [here](#configuration-object). When a port is specified, the server will wait for it to be available before starting. For continuous integration, you may want to use the `strict` option which ensures that the port is available before starting the server.--The port gets then passed over to Playwright as a [`param: baseURL`] when creating the context [`method: Browser.newContext`].--```js js-flavor=ts-// playwright.config.ts-import { PlaywrightTestConfig } from '@playwright/test';--const config: PlaywrightTestConfig = {- launch: {- command: 'npm run start',- waitForPort: 3000,- waitForPortTimeout: 120 * 1000,- strict: !!process.env.CI,- },-};--export default config;-```--```js js-flavor=js-// playwright.config.js-// @ts-check-/** @type {import('@playwright/test').PlaywrightTestConfig} */-const config = {- launch: {- command: 'npm run start',- waitForPort: 3000,- waitForPortTimeout: 120 * 1000,- strict: !!process.env.CI,- },-};--mode.exports = config;-```--Now you can use a relative path when navigating the page, or use `baseURL` fixture:--```js js-flavor=ts-// test.spec.ts-import { test } = from '@playwright/test';--test('test', async ({ page, baseURL }) => {- // baseURL is taken directly from your web server,- // e.g. http://localhost:3000- await page.goto(baseURL + '/bar');-- // Alternatively, just use relative path, because baseURL is already- // set for the default context and page.- // For example, this will result in http://localhost:3000/foo- await page.goto('/foo');-});-```--```js js-flavor=js-// test.spec.js-const { test } = require('@playwright/test');--test('test', async ({ page, baseURL }) => {- // baseURL is taken directly from your web server,- // e.g. http://localhost:3000- await page.goto(baseURL + '/bar');-- // Alternatively, just use relative path, because baseURL is already- // set for the default context and page.- // For example, this will result in http://localhost:3000/foo- await page.goto('/foo');-});-```-## Global setup and teardownTo set something up once before running all tests, use `globalSetup` option in the [configuration file](#configuration-object).diff --git a/docs/src/test-configuration.md b/docs/src/test-configuration.mdindex 3cb984a7b9..64f7cfb0f6 100644--- a/docs/src/test-configuration.md+++ b/docs/src/test-configuration.md@@ -478,7 +478,6 @@ In addition to configuring [Browser] or [BrowserContext], videos or screenshots,- `testIgnore`: Glob patterns or regular expressions that should be ignored when looking for the test files. For example, `'**/test-assets'`.- `testMatch`: Glob patterns or regular expressions that match test files. For example, `'**/todo-tests/*.spec.ts'`. By default, Playwright Test runs `.*(test|spec)\.(js|ts|mjs)` files.- `timeout`: Time in milliseconds given to each test.-- `launch: { command: string, waitForPort?: number, waitForPortTimeout?: number, strict?: boolean, cwd?: string, env?: object }` - Launch a process before the tests will start. When using `waitForPort` it will wait until the server is available, see [launch server](./test-advanced.md#launching-a-development-web-server-during-the-tests) configuration for examples. `strict` will verify that the `waitForPort` port is available instead of using it by default.- `workers`: The maximum number of concurrent worker processes to use for parallelizing tests.You can specify these options in the configuration file. Note that testing options are **top-level**, do not put them into the `use` section.diff --git a/src/test/loader.ts b/src/test/loader.tsindex 8ad810ec86..19ddcd01dc 100644--- a/src/test/loader.ts+++ b/src/test/loader.ts@@ -101,7 +101,7 @@ export class Loader {this._fullConfig.shard = takeFirst(this._configOverrides.shard, this._config.shard, baseFullConfig.shard);this._fullConfig.updateSnapshots = takeFirst(this._configOverrides.updateSnapshots, this._config.updateSnapshots, baseFullConfig.updateSnapshots);this._fullConfig.workers = takeFirst(this._configOverrides.workers, this._config.workers, baseFullConfig.workers);- this._fullConfig.launch = takeFirst(toLaunchServers(this._configOverrides.launch), toLaunchServers(this._config.launch), baseFullConfig.launch);+ this._fullConfig._launch = takeFirst(toLaunchServers(this._configOverrides._launch), toLaunchServers(this._config._launch), baseFullConfig._launch);for (const project of projects)this._addProject(project, this._fullConfig.rootDir);@@ -435,7 +435,7 @@ const baseFullConfig: FullConfig = {shard: null,updateSnapshots: 'missing',workers: 1,- launch: [],+ _launch: [],};function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {diff --git a/src/test/runner.ts b/src/test/runner.tsindex 54baa57891..d5e7707984 100644--- a/src/test/runner.ts+++ b/src/test/runner.ts@@ -167,7 +167,7 @@ export class Runner {testFiles.forEach(file => allTestFiles.add(file));}- const launchServers = await LaunchServers.create(config.launch);+ const launchServers = await LaunchServers.create(config._launch);let globalSetupResult: any;if (config.globalSetup)globalSetupResult = await (await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup'))(this._loader.fullConfig());diff --git a/tests/playwright-test/launch-server.spec.ts b/tests/playwright-test/launch-server.spec.tsindex 622aecd022..2f01ea64b8 100644--- a/tests/playwright-test/launch-server.spec.ts+++ b/tests/playwright-test/launch-server.spec.ts@@ -32,7 +32,7 @@ test('should create a server', async ({ runInlineTest }, { workerIndex }) => {`,'playwright.config.ts': `module.exports = {- launch: {+ _launch: {command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',waitForPort: ${port},},@@ -82,7 +82,7 @@ test('should create a server with environment variables', async ({ runInlineTest`,'playwright.config.ts': `module.exports = {- launch: {+ _launch: {command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',waitForPort: ${port},env: {@@ -110,7 +110,7 @@ test('should time out waiting for a server', async ({ runInlineTest }, { workerI`,'playwright.config.ts': `module.exports = {- launch: {+ _launch: {command: 'node ${JSON.stringify(JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js')))} ${port}',waitForPort: ${port},waitForPortTimeout: 100,@@ -169,7 +169,7 @@ test('should be able to use an existing server when strict is false ', async ({`,'playwright.config.ts': `module.exports = {- launch: {+ _launch: {command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',waitForPort: ${port},strict: false,@@ -202,7 +202,7 @@ test('should throw when a server is already running on the given port and strict`,'playwright.config.ts': `module.exports = {- launch: {+ _launch: {command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',waitForPort: ${port},strict: true,@@ -228,7 +228,7 @@ test('should create multiple servers', async ({ runInlineTest }, { workerIndex }`,'playwright.config.ts': `module.exports = {- launch: [{+ _launch: [{command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port1}',waitForPort: ${port1},},{diff --git a/types/test.d.ts b/types/test.d.tsindex 3c7d09cf47..6c45b5fda4 100644--- a/types/test.d.ts+++ b/types/test.d.ts@@ -240,7 +240,7 @@ interface ConfigBase {/*** Launch a web server before running tests.*/- launch?: LaunchConfig | LaunchConfig[];+ _launch?: LaunchConfig | LaunchConfig[];/*** The maximum number of concurrent worker processes to use for parallelizing tests.@@ -275,7 +275,7 @@ export interface FullConfig {shard: Shard;updateSnapshots: UpdateSnapshots;workers: number;- launch: LaunchConfig[];+ _launch: LaunchConfig[];}export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped';