Skip to content

Commit

Permalink
feat(roll): roll to ToT Playwright (07-08-24) (#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
playwrightmachine authored Aug 7, 2024
1 parent 596a1ae commit 0780b50
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
10 changes: 8 additions & 2 deletions dotnet/docs/api/class-route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await Route.AbortAsync(errorCode);

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>route.ContinueAsync</x-search>

Continues route's request with optional overrides.
Sends route's request to the network with optional overrides.

**Usage**

Expand Down Expand Up @@ -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}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.23</font><x-search>route.FallbackAsync</x-search>

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.
Expand Down Expand Up @@ -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]?&lt;[string], [string]&gt; *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="route-fallback-option-headers"/><a href="#route-fallback-option-headers" class="list-anchor">#</a>
Expand Down
10 changes: 8 additions & 2 deletions java/docs/api/class-route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ Route.abort(errorCode);

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.23</font><x-search>route.fallback</x-search>

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.
Expand Down Expand Up @@ -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]&lt;[String], [String]&gt; *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="route-fallback-option-headers"/><a href="#route-fallback-option-headers" class="list-anchor">#</a>
Expand Down Expand Up @@ -263,7 +267,7 @@ Route.request();

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>route.resume</x-search>

Continues route's request with optional overrides.
Sends route's request to the network with optional overrides.

**Usage**

Expand Down Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions nodejs/docs/api/class-route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ await route.abort(errorCode);

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>route.continue</x-search>

Continues route's request with optional overrides.
Sends route's request to the network with optional overrides.

**Usage**

Expand Down Expand Up @@ -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}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.23</font><x-search>route.fallback</x-search>

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.
Expand Down Expand Up @@ -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]&lt;[string], [string]&gt; *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="route-fallback-option-headers"/><a href="#route-fallback-option-headers" class="list-anchor">#</a>
Expand Down
5 changes: 4 additions & 1 deletion nodejs/docs/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions nodejs/docs/test-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Complete set of Playwright Test options is available in the [configuration file]
| `--shard <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 <number>` | Maximum timeout in milliseconds for each test, defaults to 30 seconds. Learn more about [various timeouts](./test-timeouts.mdx).|
| `--trace <mode>` | Force tracing mode, can be `on`, `off`, `on-first-retry`, `on-all-retries`, `retain-on-failure` |
| `--tsconfig <path>` | 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 <number>` or `-j <number>`| The maximum number of concurrent worker processes that run in [parallel](./test-parallel.mdx). |
Expand Down
28 changes: 22 additions & 6 deletions nodejs/docs/test-typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand All @@ -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".
}
Expand All @@ -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`.
Expand Down
10 changes: 8 additions & 2 deletions python/docs/api/class-route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ route.abort(**kwargs)

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>route.continue_</x-search>

Continues route's request with optional overrides.
Sends route's request to the network with optional overrides.

**Usage**

Expand Down Expand Up @@ -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}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.23</font><x-search>route.fallback</x-search>

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.

<Tabs
groupId="python-flavor"
defaultValue="sync"
Expand Down Expand Up @@ -266,6 +270,8 @@ await page.route("**/*", handle)
</TabItem>
</Tabs>

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)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="route-fallback-option-headers"/><a href="#route-fallback-option-headers" class="list-anchor">#</a>

Expand Down

0 comments on commit 0780b50

Please sign in to comment.