Skip to content

Commit 0b7b6cf

Browse files
feat(roll): roll to 1.24 Playwright (microsoft#712)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ad116a4 commit 0b7b6cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1846
-1280
lines changed

dotnet/versioned_docs/version-stable/api-testing.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using Microsoft.Playwright.NUnit;
4242
using Microsoft.Playwright;
4343
using NUnit.Framework;
4444

45-
namespace Playwright.TestingHarnessTest.NUnit
45+
namespace PlaywrightTests
4646
{
4747

4848
public class TestGitHubAPI : PlaywrightTest
@@ -95,7 +95,7 @@ using Microsoft.Playwright.NUnit;
9595
using Microsoft.Playwright;
9696
using NUnit.Framework;
9797

98-
namespace Playwright.TestingHarnessTest.NUnit
98+
namespace PlaywrightTests
9999
{
100100

101101
public class TestGitHubAPI : PlaywrightTest
@@ -220,7 +220,7 @@ using Microsoft.Playwright.NUnit;
220220
using Microsoft.Playwright;
221221
using NUnit.Framework;
222222

223-
namespace Playwright.TestingHarnessTest.NUnit
223+
namespace PlaywrightTests
224224
{
225225

226226
public class TestGitHubAPI : PlaywrightTest

dotnet/versioned_docs/version-stable/api/class-browsertype.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BrowserTypeExamples
4545
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="browser-type-connect-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds to wait for the connection to be established. Defaults to `0` (no timeout). <font size="2">Added in: v1.10</font><a href="#browser-type-connect-option-timeout" class="list-anchor">#</a>
4646
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="browser-type-connect-return"/> &#60;[Browser]&#62;<a href="#browser-type-connect-return" class="list-anchor">#</a>
4747

48-
This method attaches Playwright to an existing browser instance.
48+
This method attaches Playwright to an existing browser instance. When connecting to another browser launched via `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is compatible with 1.2.x).
4949

5050
## BrowserType.ConnectOverCDPAsync(endpointURL, options) {#browser-type-connect-over-cdp}
5151

dotnet/versioned_docs/version-stable/codegen.mdx

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,77 @@ import TabItem from '@theme/TabItem';
88
Playwright comes with the ability to generate tests out of the box and is a great way to quickly get started with testing. It will open two windows, a browser window where you interact with the website you wish to test and the Playwright Inspector window where you can record your tests, copy the tests, clear your tests as well as change the language of your tests.
99

1010
```bash
11-
pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
11+
pwsh bin\Debug\netX\playwright.ps1 codegen playwright.dev
1212
```
1313

1414
Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `codegen` will attempt to generate resilient text-based selectors.
1515

16-
<img width="1916" alt="image" src="https://user-images.githubusercontent.com/13063165/177550119-4e202a56-7d8e-43ac-ad91-bf2f7b2579bd.png"/>
16+
<img width="1183" alt="Codegen generating code for tests for playwright.dev website" src="https://user-images.githubusercontent.com/13063165/181852815-971c10da-0b55-4e54-8a73-77e1e825193c.png" />
17+
18+
## Emulate viewport size
19+
20+
Playwright opens a browser window with it's viewport set to a specific width and height and is not responsive as tests need to be run under the same conditions. Use the `--viewport` option to generate tests with a different viewport size.
21+
22+
```bash
23+
pwsh bin\Debug\netX\playwright.ps1 codegen --viewport-size=800,600 playwright.dev
24+
```
25+
26+
<img width="1409" alt="Codegen generating code for tests for playwright.dev website with a specific viewport" src="https://user-images.githubusercontent.com/13063165/182360039-6db79ad6-fe82-4fd6-900a-b5e25f7f720f.png" />
27+
28+
## Emulate devices
29+
30+
Record scripts and tests while emulating a mobile device using the `--device` option which sets the viewport size and user agent among others.
31+
32+
```bash
33+
pwsh bin\Debug\netX\playwright.ps1 codegen --device="iPhone 11" playwright.dev
34+
```
35+
36+
<img width="1239" alt="Codegen generating code for tests for playwright.dev website emulated for iPhone 11" src="https://user-images.githubusercontent.com/13063165/182360089-9dc6d33d-480e-4bb2-86a3-fec51c1c228e.png" />
37+
38+
## Emulate color scheme
39+
40+
Record scripts and tests while emulating the color scheme with the `--color-scheme` option.
41+
42+
```bash
43+
pwsh bin\Debug\netX\playwright.ps1 codegen --color-scheme=dark playwright.dev
44+
```
45+
46+
<img width="1258" alt="Codegen generating code for tests for playwright.dev website in dark mode" src="https://user-images.githubusercontent.com/13063165/182359371-0bb4a7a2-abbb-4f73-8550-d67e0101f0ad.png" />
47+
48+
## Emulate geolocation, language and timezone
49+
50+
Record scripts and tests while emulating timezone, language & location using the `--timezone`, `--geolocation` and `--lang` options. Once page opens, click the "show your location" icon at them bottom right corner of the map to see geolocation in action.
51+
52+
```bash
53+
pwsh bin\Debug\netX\playwright.ps1 codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
54+
```
55+
56+
<img width="1276" alt="Codegen generating code for tests for google maps showing timezone, geoloation as Rome, Italy and in Italian language" src="https://user-images.githubusercontent.com/13063165/182394434-73e1c2a8-767e-411a-94e4-0912c1c50ecc.png" />
1757

1858
## Preserve authenticated state
1959

20-
Run `codegen` with `--save-storage` to save [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) at the end of the session. This is useful to separately record authentication step and reuse it later in the tests.
60+
Run `codegen` with `--save-storage` to save [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) at the end of the session. This is useful to separately record an authentication step and reuse it later in the tests.
61+
62+
After performing authentication and closing the browser, `auth.json` will contain the storage state.
2163

2264
```bash
2365
pwsh bin\Debug\netX\playwright.ps1 codegen --save-storage=auth.json
24-
# Perform authentication and exit.
25-
# auth.json will contain the storage state.
2666
```
2767

28-
Run with `--load-storage` to consume previously loaded storage. This way, all [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) will be restored, bringing most web apps to the authenticated state.
68+
<img width="1264" alt="Screenshot 2022-08-03 at 13 28 02" src="https://user-images.githubusercontent.com/13063165/182599605-df2fbd05-622b-4cd7-8a32-0abdfea7d38d.png" />
69+
70+
Run with `--load-storage` to consume previously loaded storage. This way, all [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) will be restored, bringing most web apps to the authenticated state without the need to login again.
2971

3072
```bash
31-
pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app
32-
pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json my.web.app
33-
# Perform actions in authenticated state.
73+
pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json github.com/microsoft/playwright
74+
```
75+
76+
<img width="1261" alt="Screenshot 2022-08-03 at 13 33 40" src="https://user-images.githubusercontent.com/13063165/182599680-05297b4e-c258-4416-8daa-b8637c1db120.png" />
77+
78+
Use the `open` command with `--load-storage` to open the saved `auth.json`.
79+
80+
```bash
81+
pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json github.com/microsoft/playwright
3482
```
3583

3684
## Record using custom setup
@@ -54,32 +102,8 @@ var page = await context.NewPageAsync();
54102
await page.PauseAsync();
55103
```
56104

57-
## Emulate devices
58-
59-
You can record scripts and tests while emulating a device.
60-
61-
```bash
62-
# Emulate iPhone 11.
63-
pwsh bin\Debug\netX\playwright.ps1 codegen --device="iPhone 11" wikipedia.org
64-
```
65-
66-
## Emulate color scheme and viewport size
67-
68-
You can also record scripts and tests while emulating various browser properties.
69-
70-
```bash
71-
# Emulate screen size and color scheme.
72-
pwsh bin\Debug\netX\playwright.ps1 codegen --viewport-size=800,600 --color-scheme=dark twitter.com
73-
```
74-
75-
## Emulate geolocation, language and timezone
76-
77-
```bash
78-
# Emulate timezone, language & location
79-
# Once page opens, click the "my location" button to see geolocation in action
80-
pwsh bin\Debug\netX\playwright.ps1 codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
81-
```
82-
105+
## What's Next
106+
- [See a trace of your tests](./trace-viewer.mdx)
83107

84108
[Accessibility]: /api/class-accessibility.mdx "Accessibility"
85109
[APIRequest]: /api/class-apirequest.mdx "APIRequest"

dotnet/versioned_docs/version-stable/inspector.mdx renamed to dotnet/versioned_docs/version-stable/debug-selectors.mdx

Lines changed: 87 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,136 @@
11
---
2-
id: inspector
3-
title: "Inspector"
2+
id: debug-selectors
3+
title: "Debugging Selectors"
44
---
55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8-
Playwright Inspector is a GUI tool that helps authoring and debugging Playwright scripts.
8+
Playwright will throw a timeout exception like `locator.click: Timeout 30000ms exceeded` when an element does not exist on the page. There are multiple ways of debugging selectors:
9+
- [Playwright Inspector](#using-playwright-inspector) to step over each Playwright API call to inspect the page.
10+
- [Browser DevTools](#using-devtools) to inspect selectors with the DevTools element panel.
11+
- [Trace Viewer](./trace-viewer.mdx) to see what the page looked like during the test run.
12+
- [Verbose API logs](#verbose-api-logs) shows [actionability checks](./actionability.mdx) when locating the element.
913

10-
<img width="712" alt="Playwright Inspector" src="https://user-images.githubusercontent.com/883973/108614092-8c478a80-73ac-11eb-9597-67dfce110e00.png"></img>
14+
## Using Playwright Inspector
1115

12-
- [Open Playwright Inspector](#open-playwright-inspector)
13-
- [Stepping through the Playwright script](#stepping-through-the-playwright-script)
14-
- [Using Browser Developer Tools](#using-browser-developer-tools)
15-
- [Debugging Selectors](#debugging-selectors)
16-
- [Recording scripts](#recording-scripts)
16+
Open the [Playwright Inspector](./debug.mdx) and click the `Explore` button to hover over elements in the screen and click them to automatically generate selectors for those elements. To verify where selector points, paste it into the inspector input field:
1717

18-
## Open Playwright Inspector
18+
<img width="602" alt="Selectors toolbar" src="https://user-images.githubusercontent.com/883973/108614696-ad5eaa00-73b1-11eb-81f5-9eebe62543a2.png"></img>
1919

20-
There are several ways of opening Playwright Inspector:
21-
- Set the `PWDEBUG` environment variable to run your scripts in debug mode. This configures Playwright for debugging and opens the inspector.
20+
## Using DevTools
2221

23-
<Tabs
24-
groupId="bash-flavor"
25-
defaultValue="bash"
26-
values={[
27-
{label: 'Bash', value: 'bash'},
28-
{label: 'PowerShell', value: 'powershell'},
29-
{label: 'Batch', value: 'batch'}
30-
]
31-
}>
32-
<TabItem value="bash">
33-
34-
```bash
35-
PWDEBUG=1 dotnet test
36-
```
37-
38-
</TabItem>
39-
<TabItem value="powershell">
40-
41-
```powershell
42-
$env:PWDEBUG=1
43-
dotnet test
44-
```
45-
46-
</TabItem>
47-
<TabItem value="batch">
48-
49-
```batch
50-
set PWDEBUG=1
51-
dotnet test
52-
```
53-
54-
</TabItem>
55-
</Tabs>
22+
You can also use the following API inside the Developer Tools Console of any browser.
5623

57-
Additional useful defaults are configured when `PWDEBUG=1` is set:
58-
- Browsers launch in the headed mode
59-
- Default timeout is set to 0 (= no timeout)
60-
- Call [Page.PauseAsync()](/api/class-page.mdx#page-pause) method from your script when running in headed browser.
24+
When running in Debug Mode with `PWDEBUG=console`, a `playwright` object is available in Developer tools console.
25+
1. Run with `PWDEBUG=console`
26+
1. Setup a breakpoint to pause the execution
27+
1. Open the console panel in browser developer tools
6128

62-
```csharp
63-
// Pause on the following line.
64-
await page.PauseAsync();
65-
```
29+
<img src="https://user-images.githubusercontent.com/284612/92536317-37dd9380-f1ee-11ea-875d-daf1b206dd56.png"></img>
6630

67-
- Use `open` or `codegen` commands in the Playwright [CLI](./cli.mdx):
31+
### playwright.$(selector)
6832

69-
```bash
70-
pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
71-
```
33+
Query Playwright selector, using the actual Playwright query engine, for example:
7234

73-
## Stepping through the Playwright script
35+
```txt
36+
> playwright.$('.auth-form >> text=Log in');
7437
75-
When `PWDEBUG=1` is set, Playwright Inspector window will be opened and the script will be paused on the first Playwright statement:
38+
<button>Log in</button>
39+
```
7640

77-
<img width="557" alt="Paused on line" src="https://user-images.githubusercontent.com/883973/108614337-71761580-73ae-11eb-9f61-3d29c52c9520.png"></img>
41+
### playwright.$$(selector)
7842

79-
Now we know what action is about to be performed and we can look into the details on that action. For example, when stopped on an input action such as `click`, the exact point Playwright is about to click is highlighted with the large red dot on the inspected page:
43+
Same as `playwright.$`, but returns all matching elements.
8044

81-
<img width="344" alt="Red dot on inspected page" src="https://user-images.githubusercontent.com/883973/108614363-b69a4780-73ae-11eb-8f5e-51f9c91ec9b4.png"></img>
45+
```txt
46+
> playwright.$$('li >> text=John')
8247
83-
By the time Playwright has paused on that click action, it has already performed actionability checks that can be found in the log:
48+
> [<li>, <li>, <li>, <li>]
49+
```
8450

85-
<img width="712" alt="Action log" src="https://user-images.githubusercontent.com/883973/108614564-72a84200-73b0-11eb-9de2-828b28d78b36.png"></img>
51+
### playwright.inspect(selector)
8652

87-
If actionability can't be reached, it'll show action as pending:
53+
Reveal element in the Elements panel (if DevTools of the respective browser supports it).
8854

89-
<img width="712" alt="Pending action" src="https://user-images.githubusercontent.com/883973/108614840-e6e3e500-73b2-11eb-998f-0cf31b2aa9a2.png"></img>
55+
```txt
56+
> playwright.inspect('text=Log in')
57+
```
9058

91-
You can step over each action using the "Step over" action (keyboard shortcut: `F10`) or resume script without further pauses (`F8`):
59+
### playwright.locator(selector)
9260

93-
<center><img width="98" alt="Stepping toolbar" src="https://user-images.githubusercontent.com/883973/108614389-f9f4b600-73ae-11eb-8df2-8d9ce9da5d5c.png"></img></center>
61+
Query Playwright element using the actual Playwright query engine, for example:
9462

95-
## Using Browser Developer Tools
63+
```txt
64+
> playwright.locator('.auth-form', { hasText: 'Log in' });
9665
97-
You can use browser developer tools in Chromium, Firefox and WebKit while running a Playwright script, with or without Playwright inspector. Developer tools help to:
98-
* Inspect the DOM tree
99-
* **See console logs** during execution (or learn how to [read logs via API](./api/class-page.mdx#page-event-console))
100-
* Check **network activity** and other developer tools features
66+
> Locator ()
67+
> - element: button
68+
> - elements: [button]
69+
```
10170

102-
:::note
103-
**For WebKit**: launching WebKit Inspector during the execution will prevent the Playwright script from executing any further.
104-
:::
71+
### playwright.highlight(selector)
10572

106-
## Debugging Selectors
107-
- Click the Explore button to hover over elements in the screen and click them to automatically generate selectors for those elements.
108-
- To verify where selector points, paste it into the inspector input field:
73+
Highlight the first occurrence of the locator:
10974

110-
<img width="602" alt="Selectors toolbar" src="https://user-images.githubusercontent.com/883973/108614696-ad5eaa00-73b1-11eb-81f5-9eebe62543a2.png"></img>
75+
```txt
76+
> playwright.hightlight('.auth-form');
77+
```
11178

112-
You can also use the following API inside the Developer Tools Console of any browser.
79+
### playwright.clear()
11380

114-
<img src="https://user-images.githubusercontent.com/284612/92536317-37dd9380-f1ee-11ea-875d-daf1b206dd56.png"></img>
81+
```txt
82+
> playwright.clear()
83+
```
11584

116-
#### playwright.$(selector)
85+
Clear existing highlights.
11786

118-
Query Playwright selector, using the actual Playwright query engine, for example:
87+
### playwright.selector(element)
11988

120-
#### playwright.$$(selector)
89+
Generates selector for the given element.
12190

122-
Same as `playwright.$`, but returns all matching elements.
91+
```txt
92+
> playwright.selector($0)
12393
124-
#### playwright.inspect(selector)
94+
"div[id="glow-ingress-block"] >> text=/.*Hello.*/"
95+
```
12596

126-
Reveal element in the Elements panel (if DevTools of the respective browser supports it).
97+
## Verbose API logs
12798

128-
#### playwright.locator(selector)
99+
Playwright supports verbose logging with the `DEBUG` environment variable.
129100

130-
Query Playwright element using the actual Playwright query engine, for example:
101+
<Tabs
102+
groupId="bash-flavor"
103+
defaultValue="bash"
104+
values={[
105+
{label: 'Bash', value: 'bash'},
106+
{label: 'PowerShell', value: 'powershell'},
107+
{label: 'Batch', value: 'batch'}
108+
]
109+
}>
110+
<TabItem value="bash">
131111

132-
#### playwright.selector(element)
112+
```bash
113+
DEBUG=pw:api dotnet run
114+
```
133115

134-
Generates selector for the given element.
116+
</TabItem>
117+
<TabItem value="powershell">
135118

136-
## Recording scripts
119+
```powershell
120+
$env:DEBUG="pw:api"
121+
dotnet run
122+
```
137123

138-
At any moment, clicking Record action enables [codegen mode](./codegen.mdx). Every action on the target page is turned into the generated script:
124+
</TabItem>
125+
<TabItem value="batch">
139126

140-
<img width="712" alt="Recorded script" src="https://user-images.githubusercontent.com/883973/108614897-85704600-73b3-11eb-8bcd-f2e129786c49.png"></img>
127+
```batch
128+
set DEBUG=pw:api
129+
dotnet run
130+
```
141131

142-
You can copy entire generated script or clear it using toolbar actions.
132+
</TabItem>
133+
</Tabs>
143134

144135
[Accessibility]: /api/class-accessibility.mdx "Accessibility"
145136
[APIRequest]: /api/class-apirequest.mdx "APIRequest"

0 commit comments

Comments
 (0)