mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
parent
4be1e479ea
commit
c8b45aa844
@ -95,7 +95,7 @@ By default, axe checks against a wide variety of accessibility rules. Some of th
|
||||
|
||||
You can constrain an accessibility scan to only run those rules which are "tagged" as corresponding to specific WCAG success criteria by using [`AxeBuilder.withTags()`](https://github.com/dequelabs/axe-core-npm/blob/develop/packages/playwright/README.md#axebuilderwithtagstags-stringarray). For example, [Accessibility Insights for Web's Automated Checks](https://accessibilityinsights.io/docs/web/getstarted/fastpass/?referrer=playwright-accessibility-testing-js) only include axe rules that test for violations of WCAG A and AA success criteria; to match that behavior, you would use the tags `wcag2a`, `wcag2aa`, `wcag21a`, and `wcag21aa`.
|
||||
|
||||
Note that [automated testing cannot detect all types of WCAG violations](#disclaimer).
|
||||
Note that automated testing cannot detect all types of WCAG violations.
|
||||
|
||||
```js
|
||||
test('should not have any automatically detectable WCAG A or AA violations', async ({ page }) => {
|
||||
|
||||
@ -1190,7 +1190,7 @@ How often a route should be used. By default it will be used every time.
|
||||
## async method: BrowserContext.routeFromHAR
|
||||
* since: v1.23
|
||||
|
||||
If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
|
||||
If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](../mock.md#replaying-from-har).
|
||||
|
||||
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`.
|
||||
|
||||
|
||||
@ -3320,7 +3320,7 @@ How often a route should be used. By default it will be used every time.
|
||||
## async method: Page.routeFromHAR
|
||||
* since: v1.23
|
||||
|
||||
If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
|
||||
If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](../mock.md#replaying-from-har).
|
||||
|
||||
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`.
|
||||
|
||||
|
||||
@ -510,7 +510,7 @@ Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn m
|
||||
## context-option-ismobile
|
||||
- `isMobile` <[boolean]>
|
||||
|
||||
Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more about [mobile emulation](../emulation.md#isMobile).
|
||||
Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more about [mobile emulation](../emulation.md#ismobile).
|
||||
|
||||
## context-option-hastouch
|
||||
- `hasTouch` <[boolean]>
|
||||
|
||||
@ -38,7 +38,7 @@ test('second', async ({ page }) => {
|
||||
});
|
||||
```
|
||||
|
||||
You can also reuse the signed-in state in the tests with [global setup](/auth.md#reuse-signed-in-state). That way you can log in only once and then skip the log in step for all of the tests.
|
||||
You can also reuse the signed-in state in the tests with [setup project](./auth.md#basic-shared-account-in-all-tests). That way you can log in only once and then skip the log in step for all of the tests.
|
||||
|
||||
### Avoid testing third-party dependencies
|
||||
|
||||
@ -71,7 +71,7 @@ page.getByRole('button', { name: 'submit' });
|
||||
|
||||
#### Use chaining and filtering
|
||||
|
||||
Locators can be [chained](./locators.md#chaining-locators) to narrow down the search to a particular part of the page.
|
||||
Locators can be [chained](./locators.md#matching-inside-a-locator) to narrow down the search to a particular part of the page.
|
||||
|
||||
```js
|
||||
const product = page.getByRole('listitem').filter({ hasText: 'Product 2' });
|
||||
@ -217,7 +217,7 @@ Playwright comes with a range of tooling to help you write tests.
|
||||
|
||||
### Test across all browsers
|
||||
|
||||
Playwright makes it easy to test your site across all [browsers](./test-configuration#multiple-browsers) no matter what platform you are on. Testing across all browsers ensures your app works for all users. In your config file you can set up projects adding the name and which browser or device to use.
|
||||
Playwright makes it easy to test your site across all [browsers](./test-projects.md#configure-projects-for-multiple-browsers) no matter what platform you are on. Testing across all browsers ensures your app works for all users. In your config file you can set up projects adding the name and which browser or device to use.
|
||||
|
||||
```js title="playwright.config.ts"
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
@ -8,7 +8,7 @@ Playwright comes with the ability to generate tests out of the box and is a grea
|
||||
**You will learn**
|
||||
|
||||
- [How to record a test](/codegen.md#recording-a-test)
|
||||
- [How to generate locators](/codegen.md#generate-locators)
|
||||
- [How to generate locators](/codegen.md#generating-locators)
|
||||
|
||||
<video width="100%" height="100%" controls muted >
|
||||
<source src="https://user-images.githubusercontent.com/13063165/197979804-c4fa3347-8fab-4526-a728-c1b2fbd079b4.mp4" type="video/mp4" />
|
||||
|
||||
@ -88,6 +88,12 @@ await using var context = await browser.NewContextAsync(iphone13);
|
||||
|
||||
<img width="458" alt="playwright.dev website emulated for iPhone 13" src="https://user-images.githubusercontent.com/13063165/220411073-76fe59f9-9a2d-463d-8e30-c19a7deca133.png" />
|
||||
|
||||
|
||||
## Devices
|
||||
* langs: java
|
||||
|
||||
Playwright can emulate various devices by specifying `setDeviceScaleFactor`, `setHasTouch`, `setIsMobile`, `setScreenSize`, `setUserAgent` and `setViewportSize` options when creating a context with [`method: Browser.newContext`].
|
||||
|
||||
## Viewport
|
||||
|
||||
The viewport is included in the device but you can override it for some tests with [`method: Page.setViewportSize`].
|
||||
|
||||
@ -86,7 +86,7 @@ With the Example.java and pom.xml above, compile and execute your new program as
|
||||
mvn compile exec:java -D exec.mainClass="org.example.App"
|
||||
```
|
||||
|
||||
Running it downloads the Playwright package and installs browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./browsers.md#installing-browsers).
|
||||
Running it downloads the Playwright package and installs browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./browsers.md#install-browsers).
|
||||
|
||||
## First script
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ In addition to the above, Playwright Test, as a full-featured Test Runner, inclu
|
||||
- [Web-First Assertions](./test-assertions.md)
|
||||
- [Reporting](./test-reporters.md)
|
||||
- [Retries](./test-retries.md)
|
||||
- [Easily Enabled Tracing](./test-configuration.md#record-test-trace)
|
||||
- [Easily Enabled Tracing](./trace-viewer-intro.md)
|
||||
- and more…
|
||||
|
||||
## Usage
|
||||
|
||||
@ -26,7 +26,7 @@ conda install playwright
|
||||
playwright install
|
||||
```
|
||||
|
||||
These commands download the Playwright package and install browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./browsers.md#installing-browsers).
|
||||
These commands download the Playwright package and install browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./browsers.md#install-browsers).
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -888,7 +888,7 @@ Attribute selectors pierce shadow DOM. To opt-out from this behavior, use `:ligh
|
||||
## Chaining selectors
|
||||
|
||||
:::warning
|
||||
We recommend [chaining locators](./locators.md#chaining-locators) instead.
|
||||
We recommend [chaining locators](./locators.md#matching-inside-a-locator) instead.
|
||||
:::
|
||||
|
||||
Selectors defined as `engine=body` or in short-form can be combined with the `>>` token, e.g. `selector1 >> selector2 >> selectors3`. When selectors are chained, the next one is queried relative to the previous one's result.
|
||||
|
||||
@ -149,12 +149,12 @@ Once you're on Playwright Test, you get a lot!
|
||||
- Run tests across **all web engines** (Chrome, Firefox, Safari) on **any popular operating system** (Windows, macOS, Ubuntu)
|
||||
- Full support for multiple origins, [(i)frames](./api/class-frame), [tabs and contexts](./pages)
|
||||
- Run tests in parallel across multiple browsers
|
||||
- Built-in test artifact collection: [video recording](./test-configuration#record-video), [screenshots](./test-configuration#automatic-screenshots) and [playwright traces](./test-configuration#record-test-trace)
|
||||
- Built-in test [artifact collection](./test-use-options.md#recording-options)
|
||||
|
||||
You also get all these ✨ awesome tools ✨ that come bundled with Playwright Test:
|
||||
- [Playwright Inspector](./debug.md)
|
||||
- [Playwright Test Code generation](./auth#code-generation)
|
||||
- [Playwright Tracing](./trace-viewer) for post-mortem debugging
|
||||
- [Playwright Test Code generation](./codegen-intro.md)
|
||||
- [Playwright Tracing](./trace-viewer.md) for post-mortem debugging
|
||||
|
||||
## Further Reading
|
||||
|
||||
|
||||
@ -157,12 +157,12 @@ Once you're on Playwright Test, you get a lot!
|
||||
- Run tests across **all web engines** (Chrome, Firefox, Safari) on **any popular operating system** (Windows, macOS, Ubuntu)
|
||||
- Full support for multiple origins, [(i)frames](./api/class-frame), [tabs and contexts](./pages)
|
||||
- Run tests in isolation in parallel across multiple browsers
|
||||
- Built-in test artifact collection: [video recording](./test-configuration#record-video), [screenshots](./test-configuration#automatic-screenshots) and [playwright traces](./test-configuration#record-test-trace)
|
||||
- Built-in test [artifact collection](./test-use-options.md#recording-options)
|
||||
|
||||
You also get all these ✨ awesome tools ✨ that come bundled with Playwright Test:
|
||||
- [Playwright Inspector](./debug.md)
|
||||
- [Playwright Test Code generation](./auth#code-generation)
|
||||
- [Playwright Tracing](./trace-viewer) for post-mortem debugging
|
||||
- [Playwright Test Code generation](./codegen-intro.md)
|
||||
- [Playwright Tracing](./trace-viewer.md) for post-mortem debugging
|
||||
|
||||
## Further Reading
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ This version was also tested against the following stable channels:
|
||||
### New APIs
|
||||
|
||||
- New options [`option: updateMode`] and [`option: updateContent`] in [`method: Page.routeFromHAR`] and [`method: BrowserContext.routeFromHAR`].
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#chaining-locators) for details.
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#matching-inside-a-locator) for details.
|
||||
- New option [`option: name`] in method [`method: Tracing.startChunk`].
|
||||
|
||||
### Browser Versions
|
||||
@ -497,7 +497,7 @@ Use the new methods [`method: Page.routeFromHAR`] or [`method: BrowserContext.ro
|
||||
await context.RouteFromHARAsync("example.har");
|
||||
```
|
||||
|
||||
Read more in [our documentation](./network#record-and-replay-requests).
|
||||
Read more in [our documentation](./mock.md#mocking-with-har-files).
|
||||
|
||||
|
||||
### Advanced Routing
|
||||
@ -676,7 +676,7 @@ This version was also tested against the following stable channels:
|
||||
await Page.Locator("article", new() { Has = Page.Locator(".highlight") }).ClickAsync();
|
||||
```
|
||||
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
- New [`method: Locator.page`]
|
||||
- [`method: Page.screenshot`] and [`method: Locator.screenshot`] now automatically hide blinking caret
|
||||
@ -704,7 +704,7 @@ This version was also tested against the following stable channels:
|
||||
await Page.Locator("li", new() { HasTextString = "My Item" })
|
||||
.Locator("button").click();
|
||||
```
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has-text)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
|
||||
### New APIs & changes
|
||||
|
||||
@ -141,7 +141,7 @@ This version was also tested against the following stable channels:
|
||||
### New APIs
|
||||
|
||||
- New options [`option: updateMode`] and [`option: updateContent`] in [`method: Page.routeFromHAR`] and [`method: BrowserContext.routeFromHAR`].
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#chaining-locators) for details.
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#matching-inside-a-locator) for details.
|
||||
- New option [`option: name`] in method [`method: Tracing.startChunk`].
|
||||
|
||||
### Browser Versions
|
||||
@ -449,7 +449,7 @@ Use the new methods [`method: Page.routeFromHAR`] or [`method: BrowserContext.ro
|
||||
context.routeFromHAR(Paths.get("example.har"));
|
||||
```
|
||||
|
||||
Read more in [our documentation](./network#record-and-replay-requests).
|
||||
Read more in [our documentation](./mock.md#mocking-with-har-files).
|
||||
|
||||
|
||||
### Advanced Routing
|
||||
@ -597,7 +597,7 @@ This version was also tested against the following stable channels:
|
||||
page.locator("article", new Page.LocatorOptions().setHas(page.locator(".highlight"))).click();
|
||||
```
|
||||
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
- New [`method: Locator.page`]
|
||||
- [`method: Page.screenshot`] and [`method: Locator.screenshot`] now automatically hide blinking caret
|
||||
@ -670,7 +670,7 @@ Read more in [our documentation](./test-assertions).
|
||||
page.locator("li", new Page.LocatorOptions().setHasText("my item"))
|
||||
.locator("button").click();
|
||||
```
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has-text)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
### Tracing Improvements
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@ npx playwright test --ui
|
||||
### New APIs
|
||||
|
||||
- New options [`option: updateMode`] and [`option: updateContent`] in [`method: Page.routeFromHAR`] and [`method: BrowserContext.routeFromHAR`].
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#chaining-locators) for details.
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#matching-inside-a-locator) for details.
|
||||
- New property [`property: TestInfo.testId`].
|
||||
- New option [`option: name`] in method [`method: Tracing.startChunk`].
|
||||
|
||||
@ -469,7 +469,7 @@ This version was also tested against the following stable channels:
|
||||
}).toPass();
|
||||
```
|
||||
|
||||
Read more in [our documentation](./test-assertions.md#retrying).
|
||||
Read more in [our documentation](./test-assertions.md#expecttopass).
|
||||
|
||||
- Automatically capture **full page screenshot** on test failure:
|
||||
```js title="playwright.config.ts"
|
||||
@ -894,7 +894,7 @@ Use the new methods [`method: Page.routeFromHAR`] or [`method: BrowserContext.ro
|
||||
await context.routeFromHAR('github.har.zip');
|
||||
```
|
||||
|
||||
Read more in [our documentation](./network#record-and-replay-requests).
|
||||
Read more in [our documentation](./mock.md#mocking-with-har-files).
|
||||
|
||||
|
||||
### Advanced Routing
|
||||
@ -1081,7 +1081,7 @@ WebServer is now considered "ready" if request to the specified url has any of t
|
||||
```
|
||||
|
||||
`expect.poll` supports most synchronous matchers, like `.toBe()`, `.toContain()`, etc.
|
||||
Read more in [our documentation](./test-assertions.md#polling).
|
||||
Read more in [our documentation](./test-assertions.md#expectpoll).
|
||||
|
||||
### Behavior Changes
|
||||
|
||||
@ -1220,7 +1220,7 @@ This version was also tested against the following stable channels:
|
||||
6 |
|
||||
```
|
||||
|
||||
Read more in [our documentation](./test-assertions#custom-error-message)
|
||||
Read more in [our documentation](./test-assertions#custom-expect-message)
|
||||
- By default, tests in a single file are run in order. If you have many independent tests in a single file, you can now
|
||||
run them in parallel with [`method: Test.describe.configure`].
|
||||
|
||||
@ -1234,7 +1234,7 @@ This version was also tested against the following stable channels:
|
||||
}).click();
|
||||
```
|
||||
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
- New [`method: Locator.page`]
|
||||
- [`method: Page.screenshot`] and [`method: Locator.screenshot`] now automatically hide blinking caret
|
||||
@ -1276,7 +1276,7 @@ This version was also tested against the following stable channels:
|
||||
```js
|
||||
await page.locator('li', { hasText: 'my item' }).locator('button').click();
|
||||
```
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has-text)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
|
||||
### Testing API improvements
|
||||
|
||||
@ -127,7 +127,7 @@ This version was also tested against the following stable channels:
|
||||
|
||||
- Custom expect message, see [test assertions documentation](./test-assertions.md#custom-expect-message).
|
||||
- New options [`option: updateMode`] and [`option: updateContent`] in [`method: Page.routeFromHAR`] and [`method: BrowserContext.routeFromHAR`].
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#chaining-locators) for details.
|
||||
- Chaining existing locator objects, see [locator docs](./locators.md#matching-inside-a-locator) for details.
|
||||
- New option [`option: name`] in method [`method: Tracing.startChunk`].
|
||||
|
||||
### Browser Versions
|
||||
@ -450,7 +450,7 @@ await context.route_from_har("github.har.zip")
|
||||
context.route_from_har("github.har.zip")
|
||||
```
|
||||
|
||||
Read more in [our documentation](./network#record-and-replay-requests).
|
||||
Read more in [our documentation](./mock.md#mocking-with-har-files).
|
||||
|
||||
|
||||
### Advanced Routing
|
||||
@ -651,7 +651,7 @@ This version was also tested against the following stable channels:
|
||||
page.locator("article", has=page.locator(".highlight")).click()
|
||||
```
|
||||
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
- New [`method: Locator.page`]
|
||||
- [`method: Page.screenshot`] and [`method: Locator.screenshot`] now automatically hide blinking caret
|
||||
@ -737,7 +737,7 @@ Read more in [our documentation](./test-assertions).
|
||||
page.locator("li", has_text="my item").locator("button").click()
|
||||
```
|
||||
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator-option-has-text)
|
||||
Read more in [locator documentation](./api/class-locator#locator-locator)
|
||||
|
||||
|
||||
### New APIs & changes
|
||||
|
||||
@ -52,8 +52,6 @@ SELENIUM_REMOTE_URL=http://<selenium-hub-ip>:4444 dotnet test
|
||||
|
||||
You don't have to change your code, just use your testing harness or [`method: BrowserType.launch`] as usual.
|
||||
|
||||
When using Selenium Grid Hub, you can [skip browser downloads](./browsers.md#skip-browser-downloads).
|
||||
|
||||
### Passing additional capabilities
|
||||
|
||||
If your grid requires additional capabilities to be set (for example, you use an external service), you can set `SELENIUM_REMOTE_CAPABILITIES` environment variable to provide JSON-serialized capabilities.
|
||||
|
||||
@ -475,7 +475,7 @@ export default defineConfig({
|
||||
});
|
||||
```
|
||||
|
||||
Learn more about [automatic screenshots](../test-configuration.md#automatic-screenshots).
|
||||
Learn more about [automatic screenshots](../test-use-options.md#recording-options).
|
||||
|
||||
## property: TestOptions.storageState = %%-js-python-context-option-storage-state-%%
|
||||
* since: v1.10
|
||||
@ -554,7 +554,7 @@ export default defineConfig({
|
||||
});
|
||||
```
|
||||
|
||||
Learn more about [recording trace](../test-configuration.md#record-test-trace).
|
||||
Learn more about [recording trace](../test-use-options.md#recording-options).
|
||||
|
||||
## property: TestOptions.userAgent = %%-context-option-useragent-%%
|
||||
* since: v1.10
|
||||
@ -599,7 +599,7 @@ export default defineConfig({
|
||||
});
|
||||
```
|
||||
|
||||
Learn more about [recording video](../test-configuration.md#record-video).
|
||||
Learn more about [recording video](../test-use-options.md#recording-options).
|
||||
|
||||
## property: TestOptions.viewport = %%-context-option-viewport-%%
|
||||
* since: v1.10
|
||||
|
||||
@ -212,7 +212,7 @@ export default defineConfig({
|
||||
|
||||
## Configure globalSetup and globalTeardown
|
||||
|
||||
You can use the `globalSetup` option in the [configuration file](#configuration-object) to set something up once before running all tests. The global setup file must export a single function that takes a config object. This function will be run once before all the tests.
|
||||
You can use the `globalSetup` option in the [configuration file](./test-configuration.md#advanced-configuration) to set something up once before running all tests. The global setup file must export a single function that takes a config object. This function will be run once before all the tests.
|
||||
|
||||
Similarly, use `globalTeardown` to run something once after all the tests. Alternatively, let `globalSetup` return a function that will be used as a global teardown. You can pass data such as port number, authentication tokens, etc. from your global setup to your tests using environment variables.
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ npx playwright test --update-snapshots
|
||||
> Note that `snapshotName` also accepts an array of path segments to the snapshot file such as `expect().toHaveScreenshot(['relative', 'path', 'to', 'snapshot.png'])`.
|
||||
> However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`), otherwise it will throw.
|
||||
|
||||
Playwright Test uses the [pixelmatch](https://github.com/mapbox/pixelmatch) library. You can [pass various options](./test-assertions#page-assertions-to-have-screenshot-2) to modify its behavior:
|
||||
Playwright Test uses the [pixelmatch](https://github.com/mapbox/pixelmatch) library. You can [pass various options](./api/class-pageassertions.md#page-assertions-to-have-screenshot-1) to modify its behavior:
|
||||
|
||||
```js title="example.spec.ts"
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
@ -204,7 +204,7 @@ export default defineConfig({
|
||||
});
|
||||
```
|
||||
|
||||
However, most common ones like `headless` or `viewport` are available directly in the `use` section - see [basic options](#basic-options), [emulation](./emulation.md) or [network](#network).
|
||||
However, most common ones like `headless` or `viewport` are available directly in the `use` section - see [basic options](#basic-options), [emulation](#emulation-options) or [network](#network-options).
|
||||
|
||||
### Explicit Context Creation and Option Inheritance
|
||||
|
||||
|
||||
@ -132,12 +132,12 @@ Once you're on Playwright Test, you get a lot!
|
||||
- Run tests across **all web engines** (Chrome, Firefox, Safari) on **any popular operating system** (Windows, macOS, Ubuntu)
|
||||
- Full support for multiple origins, [(i)frames](./api/class-frame), [tabs and contexts](./pages)
|
||||
- Run tests in isolation in parallel across multiple browsers
|
||||
- Built-in test artifact collection: [video recording](./test-configuration#record-video), [screenshots](./test-configuration#automatic-screenshots) and [playwright traces](./test-configuration#record-test-trace)
|
||||
- Built-in test [artifact collection](./test-use-options.md#recording-options)
|
||||
|
||||
You also get all these ✨ awesome tools ✨ that come bundled with Playwright Test:
|
||||
- [Playwright Inspector](./debug.md)
|
||||
- [Playwright Test Code generation](./auth#code-generation)
|
||||
- [Playwright Tracing](./trace-viewer) for post-mortem debugging
|
||||
- [Playwright Test Code generation](./codegen-intro.md)
|
||||
- [Playwright Tracing](./trace-viewer.md) for post-mortem debugging
|
||||
|
||||
## Further Reading
|
||||
|
||||
|
||||
20
packages/playwright-core/types/types.d.ts
vendored
20
packages/playwright-core/types/types.d.ts
vendored
@ -3600,7 +3600,7 @@ export interface Page {
|
||||
|
||||
/**
|
||||
* If specified the network requests that are made in the page will be served from the HAR file. Read more about
|
||||
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
|
||||
* [Replaying from HAR](https://playwright.dev/docs/mock#replaying-from-har).
|
||||
*
|
||||
* Playwright will not serve requests intercepted by Service Worker from the HAR file. See
|
||||
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when
|
||||
@ -8327,7 +8327,7 @@ export interface BrowserContext {
|
||||
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
|
||||
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
|
||||
* [Replaying from HAR](https://playwright.dev/docs/mock#replaying-from-har).
|
||||
*
|
||||
* Playwright will not serve requests intercepted by Service Worker from the HAR file. See
|
||||
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when
|
||||
@ -12738,7 +12738,7 @@ export interface BrowserType<Unused = {}> {
|
||||
/**
|
||||
* Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#isMobile).
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
|
||||
*/
|
||||
isMobile?: boolean;
|
||||
|
||||
@ -12959,7 +12959,7 @@ export interface BrowserType<Unused = {}> {
|
||||
videosPath?: string;
|
||||
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).
|
||||
*
|
||||
* **NOTE** The `null` value opts out from the default presets, makes viewport depend on the host window size defined
|
||||
@ -14145,7 +14145,7 @@ export interface AndroidDevice {
|
||||
/**
|
||||
* Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#isMobile).
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
|
||||
*/
|
||||
isMobile?: boolean;
|
||||
|
||||
@ -14349,7 +14349,7 @@ export interface AndroidDevice {
|
||||
videosPath?: string;
|
||||
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).
|
||||
*
|
||||
* **NOTE** The `null` value opts out from the default presets, makes viewport depend on the host window size defined
|
||||
@ -16020,7 +16020,7 @@ export interface Browser extends EventEmitter {
|
||||
/**
|
||||
* Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#isMobile).
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
|
||||
*/
|
||||
isMobile?: boolean;
|
||||
|
||||
@ -16284,7 +16284,7 @@ export interface Browser extends EventEmitter {
|
||||
videosPath?: string;
|
||||
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).
|
||||
*
|
||||
* **NOTE** The `null` value opts out from the default presets, makes viewport depend on the host window size defined
|
||||
@ -19157,7 +19157,7 @@ export interface BrowserContextOptions {
|
||||
/**
|
||||
* Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#isMobile).
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
|
||||
*/
|
||||
isMobile?: boolean;
|
||||
|
||||
@ -19421,7 +19421,7 @@ export interface BrowserContextOptions {
|
||||
videosPath?: string;
|
||||
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).
|
||||
*
|
||||
* **NOTE** The `null` value opts out from the default presets, makes viewport depend on the host window size defined
|
||||
|
||||
10
packages/playwright-test/types/test.d.ts
vendored
10
packages/playwright-test/types/test.d.ts
vendored
@ -3575,7 +3575,7 @@ export interface PlaywrightWorkerOptions {
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Learn more about [automatic screenshots](https://playwright.dev/docs/test-configuration#automatic-screenshots).
|
||||
* Learn more about [automatic screenshots](https://playwright.dev/docs/test-use-options#recording-options).
|
||||
*/
|
||||
screenshot: ScreenshotMode | { mode: ScreenshotMode } & Pick<PageScreenshotOptions, 'fullPage' | 'omitBackground'>;
|
||||
/**
|
||||
@ -3601,7 +3601,7 @@ export interface PlaywrightWorkerOptions {
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Learn more about [recording trace](https://playwright.dev/docs/test-configuration#record-test-trace).
|
||||
* Learn more about [recording trace](https://playwright.dev/docs/test-use-options#recording-options).
|
||||
*/
|
||||
trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean, attachments?: boolean };
|
||||
/**
|
||||
@ -3629,7 +3629,7 @@ export interface PlaywrightWorkerOptions {
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Learn more about [recording video](https://playwright.dev/docs/test-configuration#record-video).
|
||||
* Learn more about [recording video](https://playwright.dev/docs/test-use-options#recording-options).
|
||||
*/
|
||||
video: VideoMode | /** deprecated */ 'retry-with-video' | { mode: VideoMode, size?: ViewportSize };
|
||||
}
|
||||
@ -3856,7 +3856,7 @@ export interface PlaywrightTestOptions {
|
||||
*
|
||||
* Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#isMobile).
|
||||
* about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
|
||||
*/
|
||||
isMobile: boolean;
|
||||
/**
|
||||
@ -4024,7 +4024,7 @@ export interface PlaywrightTestOptions {
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use `null` to disable the consistent
|
||||
* viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).
|
||||
*
|
||||
* **NOTE** The `null` value opts out from the default presets, makes viewport depend on the host window size defined
|
||||
|
||||
@ -24,6 +24,7 @@ const { parseApi } = require('./api_parser');
|
||||
const missingDocs = require('./missingDocs');
|
||||
const md = require('../markdown');
|
||||
const docs = require('./documentation');
|
||||
const toKebabCase = require('lodash/kebabCase')
|
||||
|
||||
/** @typedef {import('./documentation').Type} Type */
|
||||
/** @typedef {import('../markdown').MarkdownNode} MarkdownNode */
|
||||
@ -147,24 +148,26 @@ async function run() {
|
||||
documentation.setCodeGroupsTransformer(lang, tabs => tabs.map(tab => tab.spec));
|
||||
documentation.generateSourceCodeComments();
|
||||
|
||||
const relevantMarkdownFiles = new Set([...getAllMarkdownFiles(documentationRoot)
|
||||
// filter out language specific files
|
||||
.filter(filePath => {
|
||||
const matches = filePath.match(/(-(js|python|csharp|java))+?/g);
|
||||
// no language specific document
|
||||
if (!matches)
|
||||
return true;
|
||||
// there is a language, lets filter for it
|
||||
return matches.includes(`-${lang}`);
|
||||
})
|
||||
// Standardise naming and remove the filter in the file name
|
||||
.map(filePath => filePath.replace(/(-(js|python|csharp|java))+/, ''))
|
||||
// Internally (playwright.dev generator) we merge test-api and test-reporter-api into api.
|
||||
.map(filePath => filePath.replace(/(\/|\\)(test-api|test-reporter-api)(\/|\\)/, `${path.sep}api${path.sep}`))]);
|
||||
const mdLinks = [];
|
||||
const mdSections = new Set();
|
||||
|
||||
for (const cls of documentation.classesArray) {
|
||||
const filePath = path.join(documentationRoot, 'api', 'class-' + cls.name.toLowerCase() + '.md');
|
||||
for (const member of cls.membersArray)
|
||||
mdSections.add(filePath + '#' + toKebabCase(cls.name).toLowerCase() + '-' + toKebabCase(member.name).toLowerCase());
|
||||
for (const event of cls.eventsArray)
|
||||
mdSections.add(filePath + '#' + toKebabCase(cls.name).toLowerCase() + '-event-' + toKebabCase(event.name).toLowerCase());
|
||||
}
|
||||
|
||||
for (const filePath of getAllMarkdownFiles(documentationRoot)) {
|
||||
if (langs.some(other => other !== lang && filePath.endsWith(`-${other}.md`)))
|
||||
if (!filePath.includes(`-${lang}`) && langs.some(other => other !== lang && filePath.includes(`-${other}`)))
|
||||
continue;
|
||||
|
||||
// Standardise naming and remove the filter in the file name
|
||||
// Also, Internally (playwright.dev generator) we merge test-api and test-reporter-api into api.
|
||||
const canonicalName = filePath.replace(/(-(js|python|csharp|java))+/, '').replace(/(\/|\\)(test-api|test-reporter-api)(\/|\\)/, `${path.sep}api${path.sep}`);
|
||||
mdSections.add(canonicalName);
|
||||
|
||||
const data = fs.readFileSync(filePath, 'utf-8');
|
||||
let rootNode = md.filterNodesForLanguage(md.parse(data), lang);
|
||||
// Validates code snippet groups.
|
||||
@ -174,33 +177,35 @@ async function run() {
|
||||
// Validate links.
|
||||
{
|
||||
md.visitAll(rootNode, node => {
|
||||
{
|
||||
if (node.type === 'code') {
|
||||
const allowedCodeLangs = new Set([
|
||||
'csharp',
|
||||
'java',
|
||||
'js',
|
||||
'ts',
|
||||
'python',
|
||||
'py',
|
||||
'java',
|
||||
'powershell',
|
||||
'batch',
|
||||
'ini',
|
||||
'txt',
|
||||
'html',
|
||||
'xml',
|
||||
'yml',
|
||||
'yaml',
|
||||
'json',
|
||||
'groovy',
|
||||
'html',
|
||||
'bash',
|
||||
'sh',
|
||||
]);
|
||||
if (!allowedCodeLangs.has(node.codeLang.split(' ')[0]))
|
||||
throw new Error(`${path.relative(PROJECT_DIR, filePath)} contains code block with invalid code block language ${node.codeLang}`);
|
||||
}
|
||||
if (node.type === 'code') {
|
||||
const allowedCodeLangs = new Set([
|
||||
'csharp',
|
||||
'java',
|
||||
'js',
|
||||
'ts',
|
||||
'python',
|
||||
'py',
|
||||
'java',
|
||||
'powershell',
|
||||
'batch',
|
||||
'ini',
|
||||
'txt',
|
||||
'html',
|
||||
'xml',
|
||||
'yml',
|
||||
'yaml',
|
||||
'json',
|
||||
'groovy',
|
||||
'html',
|
||||
'bash',
|
||||
'sh',
|
||||
]);
|
||||
if (!allowedCodeLangs.has(node.codeLang.split(' ')[0]))
|
||||
throw new Error(`${path.relative(PROJECT_DIR, filePath)} contains code block with invalid code block language ${node.codeLang}`);
|
||||
}
|
||||
if (node.type.startsWith('h')) {
|
||||
const hash = mdSectionHash(node.text || '');
|
||||
mdSections.add(canonicalName + '#' + hash);
|
||||
}
|
||||
if (!node.text)
|
||||
return;
|
||||
@ -208,21 +213,29 @@ async function run() {
|
||||
const isExternal = mdLink.startsWith('http://') || mdLink.startsWith('https://');
|
||||
if (isExternal)
|
||||
continue;
|
||||
// ignore links with only a hash (same file)
|
||||
if (mdLink.startsWith('#'))
|
||||
continue;
|
||||
|
||||
let markdownBasePath = path.dirname(filePath);
|
||||
let linkWithoutHash = path.join(markdownBasePath, mdLink.split('#')[0]);
|
||||
if (path.extname(linkWithoutHash) !== '.md')
|
||||
linkWithoutHash += '.md';
|
||||
|
||||
if (!relevantMarkdownFiles.has(linkWithoutHash))
|
||||
throw new Error(`${path.relative(PROJECT_DIR, filePath)} references to '${linkWithoutHash}' as '${mdLinkName}' which does not exist.`);
|
||||
const [beforeHash, hash] = mdLink.split('#');
|
||||
let linkWithoutHash = canonicalName;
|
||||
if (beforeHash) {
|
||||
// Not same-file link.
|
||||
linkWithoutHash = path.join(path.dirname(filePath), beforeHash);
|
||||
if (path.extname(linkWithoutHash) !== '.md')
|
||||
linkWithoutHash += '.md';
|
||||
}
|
||||
mdLinks.push({ filePath, linkTarget: linkWithoutHash + (hash ? '#' + hash : ''), name: mdLinkName });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const badLinks = [];
|
||||
for (const { filePath, linkTarget, name } of mdLinks) {
|
||||
if (!mdSections.has(linkTarget))
|
||||
badLinks.push(`${path.relative(PROJECT_DIR, filePath)} references to '${linkTarget}' as '${name}' which does not exist.`);
|
||||
}
|
||||
if (badLinks.length)
|
||||
throw new Error('Broken links found:\n' + badLinks.join('\n'));
|
||||
|
||||
} catch (e) {
|
||||
e.message = `While processing "${lang}"\n` + e.message;
|
||||
throw e;
|
||||
@ -280,3 +293,7 @@ async function getBrowserVersions() {
|
||||
await Promise.all(browsers.map(browser => browser.close()));
|
||||
return result;
|
||||
}
|
||||
|
||||
function mdSectionHash(text) {
|
||||
return text.toLowerCase().replace(/\s/g, '-').replace(/[^-_a-z0-9]/g, '').replace(/^-+/, '');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user