From 0780b50fe22697c358bebcd4987d76cd70fb50f3 Mon Sep 17 00:00:00 2001 From: Playwright Service <89237858+playwrightmachine@users.noreply.github.com> Date: Wed, 7 Aug 2024 03:13:59 -0700 Subject: [PATCH] feat(roll): roll to ToT Playwright (07-08-24) (#1463) --- dotnet/docs/api/class-route.mdx | 10 ++++++++-- java/docs/api/class-route.mdx | 10 ++++++++-- nodejs/docs/api/class-route.mdx | 10 ++++++++-- nodejs/docs/auth.mdx | 5 ++++- nodejs/docs/test-cli.mdx | 1 + nodejs/docs/test-typescript.mdx | 28 ++++++++++++++++++++++------ python/docs/api/class-route.mdx | 10 ++++++++-- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/dotnet/docs/api/class-route.mdx b/dotnet/docs/api/class-route.mdx index 05fa38380d..718da42d68 100644 --- a/dotnet/docs/api/class-route.mdx +++ b/dotnet/docs/api/class-route.mdx @@ -56,7 +56,7 @@ await Route.AbortAsync(errorCode); Added before v1.9route.ContinueAsync -Continues route's request with optional overrides. +Sends route's request to the network with optional overrides. **Usage** @@ -91,16 +91,20 @@ await page.RouteAsync("**/*", async route => Note that any overrides such as `url` or `headers` only apply to the request being routed. If this request results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header through redirects, use the combination of [Route.FetchAsync()](/api/class-route.mdx#route-fetch) and [Route.FulfillAsync()](/api/class-route.mdx#route-fulfill) instead. +[Route.ContinueAsync()](/api/class-route.mdx#route-continue) will immediately send the request to the network, other matching handlers won't be invoked. Use [Route.FallbackAsync()](/api/class-route.mdx#route-fallback) If you want next matching handler in the chain to be invoked. + --- ### FallbackAsync {#route-fallback} Added in: v1.23route.FallbackAsync -When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. +Continues route's request with optional overrides. The method is similar to [Route.ContinueAsync()](/api/class-route.mdx#route-continue) with the difference that other matching handlers will be invoked before sending the request. **Usage** +When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. + ```csharp await page.RouteAsync("**/*", route => { // Runs last. @@ -153,6 +157,8 @@ await page.RouteAsync("**/*", async route => }); ``` +Use [Route.ContinueAsync()](/api/class-route.mdx#route-continue) to immediately send the request to the network, other matching handlers won't be invoked in that case. + **Arguments** - `options` `RouteFallbackOptions?` *(optional)* - `Headers` [IDictionary]?<[string], [string]> *(optional)*# diff --git a/java/docs/api/class-route.mdx b/java/docs/api/class-route.mdx index 40f7722ce4..998e50c1c0 100644 --- a/java/docs/api/class-route.mdx +++ b/java/docs/api/class-route.mdx @@ -57,10 +57,12 @@ Route.abort(errorCode); Added in: v1.23route.fallback -When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. +Continues route's request with optional overrides. The method is similar to [Route.resume()](/api/class-route.mdx#route-continue) with the difference that other matching handlers will be invoked before sending the request. **Usage** +When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. + ```java page.route("**/*", route -> { // Runs last. @@ -114,6 +116,8 @@ page.route("**/*", route -> { }); ``` +Use [Route.resume()](/api/class-route.mdx#route-continue) to immediately send the request to the network, other matching handlers won't be invoked in that case. + **Arguments** - `options` `Route.FallbackOptions` *(optional)* - `setHeaders` [Map]<[String], [String]> *(optional)*# @@ -263,7 +267,7 @@ Route.request(); Added before v1.9route.resume -Continues route's request with optional overrides. +Sends route's request to the network with optional overrides. **Usage** @@ -299,6 +303,8 @@ page.route("**/*", route -> { Note that any overrides such as `url` or `headers` only apply to the request being routed. If this request results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header through redirects, use the combination of [Route.fetch()](/api/class-route.mdx#route-fetch) and [Route.fulfill()](/api/class-route.mdx#route-fulfill) instead. +[Route.resume()](/api/class-route.mdx#route-continue) will immediately send the request to the network, other matching handlers won't be invoked. Use [Route.fallback()](/api/class-route.mdx#route-fallback) If you want next matching handler in the chain to be invoked. + [APIRequest]: /api/class-apirequest.mdx "APIRequest" [APIRequestContext]: /api/class-apirequestcontext.mdx "APIRequestContext" diff --git a/nodejs/docs/api/class-route.mdx b/nodejs/docs/api/class-route.mdx index 54f9813a41..7db0cd7200 100644 --- a/nodejs/docs/api/class-route.mdx +++ b/nodejs/docs/api/class-route.mdx @@ -57,7 +57,7 @@ await route.abort(errorCode); Added before v1.9route.continue -Continues route's request with optional overrides. +Sends route's request to the network with optional overrides. **Usage** @@ -95,16 +95,20 @@ await page.route('**/*', async (route, request) => { Note that any overrides such as `url` or `headers` only apply to the request being routed. If this request results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header through redirects, use the combination of [route.fetch()](/api/class-route.mdx#route-fetch) and [route.fulfill()](/api/class-route.mdx#route-fulfill) instead. +[route.continue()](/api/class-route.mdx#route-continue) will immediately send the request to the network, other matching handlers won't be invoked. Use [route.fallback()](/api/class-route.mdx#route-fallback) If you want next matching handler in the chain to be invoked. + --- ### fallback {#route-fallback} Added in: v1.23route.fallback -When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. +Continues route's request with optional overrides. The method is similar to [route.continue()](/api/class-route.mdx#route-continue) with the difference that other matching handlers will be invoked before sending the request. **Usage** +When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. + ```js await page.route('**/*', async route => { // Runs last. @@ -158,6 +162,8 @@ await page.route('**/*', async (route, request) => { }); ``` +Use [route.continue()](/api/class-route.mdx#route-continue) to immediately send the request to the network, other matching handlers won't be invoked in that case. + **Arguments** - `options` [Object] *(optional)* - `headers` [Object]<[string], [string]> *(optional)*# diff --git a/nodejs/docs/auth.mdx b/nodejs/docs/auth.mdx index 486da62f52..674ef6cdad 100644 --- a/nodejs/docs/auth.mdx +++ b/nodejs/docs/auth.mdx @@ -69,8 +69,9 @@ Create `tests/auth.setup.ts` that will prepare authenticated browser state for a ```js title="tests/auth.setup.ts" import { test as setup, expect } from '@playwright/test'; +import path from 'path'; -const authFile = 'playwright/.auth/user.json'; +const authFile = path.join(__dirname, '../playwright/.auth/user.json'); setup('authenticate', async ({ page }) => { // Perform authentication steps. Replace these actions with your own. @@ -135,6 +136,8 @@ test('test', async ({ page }) => { }); ``` +Note that you need to delete the stored state when it expires. If you don't need to keep the state between test runs, write the browser state under [testProject.outputDir](/api/class-testproject.mdx#test-project-output-dir), which is automatically cleaned up before every test run. + ### Authenticating in UI mode UI mode will not run the `setup` project by default to improve testing speed. We recommend to authenticate by manually running the `auth.setup.ts` from time to time, whenever existing authentication expires. diff --git a/nodejs/docs/test-cli.mdx b/nodejs/docs/test-cli.mdx index 27778e0594..e84b60f0ea 100644 --- a/nodejs/docs/test-cli.mdx +++ b/nodejs/docs/test-cli.mdx @@ -118,6 +118,7 @@ Complete set of Playwright Test options is available in the [configuration file] | `--shard ` | [Shard](./test-parallel.mdx#shard-tests-between-multiple-machines) tests and execute only selected shard, specified in the form `current/all`, 1-based, for example `3/5`.| | `--timeout ` | Maximum timeout in milliseconds for each test, defaults to 30 seconds. Learn more about [various timeouts](./test-timeouts.mdx).| | `--trace ` | Force tracing mode, can be `on`, `off`, `on-first-retry`, `on-all-retries`, `retain-on-failure` | +| `--tsconfig ` | Path to a single tsconfig applicable to all imported files. See [tsconfig resolution](./test-typescript.mdx#tsconfig-resolution) for more details. | | `--update-snapshots` or `-u` | Whether to update [snapshots](./test-snapshots.mdx) with actual results instead of comparing them. Use this when snapshot expectations have changed.| | `--workers ` or `-j `| The maximum number of concurrent worker processes that run in [parallel](./test-parallel.mdx). | diff --git a/nodejs/docs/test-typescript.mdx b/nodejs/docs/test-typescript.mdx index 44ea56e3e3..5f4381b59b 100644 --- a/nodejs/docs/test-typescript.mdx +++ b/nodejs/docs/test-typescript.mdx @@ -8,9 +8,9 @@ import HTMLCard from '@site/src/components/HTMLCard'; ## Introduction -Playwright supports TypeScript out of the box. You just write tests in TypeScript, and Playwright will read them, transform to JavaScript and run. Note that Playwright does not check the types and will run tests even if there are non-critical TypeScript compilation errors. +Playwright supports TypeScript out of the box. You just write tests in TypeScript, and Playwright will read them, transform to JavaScript and run. -We recommend you run TypeScript compiler alongside Playwright. For example on GitHub actions: +Note that Playwright does not check the types and will run tests even if there are non-critical TypeScript compilation errors. We recommend you run TypeScript compiler alongside Playwright. For example on GitHub actions: ```yaml jobs: @@ -32,7 +32,7 @@ npx tsc -p tsconfig.json --noEmit -w ## tsconfig.json -Playwright will pick up `tsconfig.json` for each source file it loads. Note that Playwright **only supports** the following tsconfig options: `paths` and `baseUrl`. +Playwright will pick up `tsconfig.json` for each source file it loads. Note that Playwright **only supports** the following tsconfig options: `allowJs`, `baseUrl`, `paths` and `references`. We recommend setting up a separate `tsconfig.json` in the tests directory so that you can change some preferences specifically for the tests. Here is an example directory structure. @@ -53,12 +53,12 @@ playwright.config.ts Playwright supports [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) declared in the `tsconfig.json`. Make sure that `baseUrl` is also set. -Here is an example `tsconfig.json` that works with Playwright Test: +Here is an example `tsconfig.json` that works with Playwright: -```json +```json title="tsconfig.json" { "compilerOptions": { - "baseUrl": ".", // This must be specified if "paths" is. + "baseUrl": ".", "paths": { "@myhelper/*": ["packages/myhelper/*"] // This mapping is relative to "baseUrl". } @@ -78,6 +78,22 @@ test('example', async ({ page }) => { }); ``` +### tsconfig resolution + +By default, Playwright will look up a closest tsconfig for each imported file by going up the directory structure and looking for `tsconfig.json` or `jsconfig.json`. This way, you can create a `tests/tsconfig.json` file that will be used only for your tests and Playwright will pick it up automatically. + +```sh +# Playwright will choose tsconfig automatically +npx playwrigh test +``` + +Alternatively, you can specify a single tsconfig file to use in the command line, and Playwright will use it for all imported files, not only test files. + +```sh +# Pass a specific tsconfig +npx playwrigh test --tsconfig=tsconfig.test.json +``` + ## Manually compile tests with TypeScript Sometimes, Playwright Test will not be able to transform your TypeScript code correctly, for example when you are using experimental or very recent features of TypeScript, usually configured in `tsconfig.json`. diff --git a/python/docs/api/class-route.mdx b/python/docs/api/class-route.mdx index 9e4ace4e2d..a563675a78 100644 --- a/python/docs/api/class-route.mdx +++ b/python/docs/api/class-route.mdx @@ -57,7 +57,7 @@ route.abort(**kwargs) Added before v1.9route.continue_ -Continues route's request with optional overrides. +Sends route's request to the network with optional overrides. **Usage** @@ -124,16 +124,20 @@ await page.route("**/*", handle) Note that any overrides such as `url` or `headers` only apply to the request being routed. If this request results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header through redirects, use the combination of [route.fetch()](/api/class-route.mdx#route-fetch) and [route.fulfill()](/api/class-route.mdx#route-fulfill) instead. +[route.continue_()](/api/class-route.mdx#route-continue) will immediately send the request to the network, other matching handlers won't be invoked. Use [route.fallback()](/api/class-route.mdx#route-fallback) If you want next matching handler in the chain to be invoked. + --- ### fallback {#route-fallback} Added in: v1.23route.fallback -When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. +Continues route's request with optional overrides. The method is similar to [route.continue_()](/api/class-route.mdx#route-continue) with the difference that other matching handlers will be invoked before sending the request. **Usage** +When several routes match the given pattern, they run in the order opposite to their registration. That way the last registered route can always override all the previous ones. In the example below, request will be handled by the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first registered route. + +Use [route.continue_()](/api/class-route.mdx#route-continue) to immediately send the request to the network, other matching handlers won't be invoked in that case. + **Arguments** - `headers` [Dict]\[[str], [str]\] *(optional)*#