Skip to content

Commit 65bf44d

Browse files
authored
docs(inspector): add initial inspector docs (#5541)
1 parent 791c8da commit 65bf44d

File tree

8 files changed

+141
-31
lines changed

8 files changed

+141
-31
lines changed

docs/src/cli.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ npx playwright --help
1414
```
1515

1616
```sh python
17-
$ python -m playwright
17+
$ playwright
1818
```
1919

2020
```json js
@@ -33,7 +33,7 @@ $ npx playwright codegen wikipedia.org
3333
```
3434

3535
```sh python
36-
$ python -m playwright codegen wikipedia.org
36+
$ playwright codegen wikipedia.org
3737
```
3838

3939
Run `codegen` and perform actions in the browser. Playwright CLI will generate JavaScript code for the user interactions. `codegen` will attempt to generate resilient text-based selectors.
@@ -51,7 +51,7 @@ $ npx playwright --save-storage=auth.json codegen
5151
```
5252

5353
```sh python
54-
$ python -m playwright --save-storage=auth.json codegen
54+
$ playwright --save-storage=auth.json codegen
5555
# Perform authentication and exit.
5656
# auth.json will contain the storage state.
5757
```
@@ -65,8 +65,8 @@ $ npx playwright --load-storage=auth.json codegen my.web.app
6565
```
6666

6767
```sh python
68-
$ python -m playwright --load-storage=auth.json open my.web.app
69-
$ python -m playwright --load-storage=auth.json codegen my.web.app
68+
$ playwright --load-storage=auth.json open my.web.app
69+
$ playwright --load-storage=auth.json codegen my.web.app
7070
# Perform actions in authenticated state.
7171
```
7272

@@ -138,7 +138,7 @@ $ npx playwright open example.com
138138

139139
```sh python
140140
# Open page in Chromium
141-
$ python -m playwright open example.com
141+
$ playwright open example.com
142142
```
143143

144144
```sh js
@@ -148,7 +148,7 @@ $ npx playwright wk example.com
148148

149149
```sh python
150150
# Open page in WebKit
151-
$ python -m playwright wk example.com
151+
$ playwright wk example.com
152152
```
153153

154154
### Emulate devices
@@ -161,7 +161,7 @@ $ npx playwright --device="iPhone 11" open wikipedia.org
161161

162162
```sh python
163163
# Emulate iPhone 11.
164-
$ python -m playwright --device="iPhone 11" open wikipedia.org
164+
$ playwright --device="iPhone 11" open wikipedia.org
165165
```
166166

167167
### Emulate color scheme and viewport size
@@ -171,7 +171,7 @@ $ npx playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
171171
```
172172
```sh python
173173
# Emulate screen size and color scheme.
174-
$ python -m playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
174+
$ playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
175175
```
176176

177177
### Emulate geolocation, language and timezone
@@ -183,7 +183,7 @@ $ npx playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --
183183
```sh python
184184
# Emulate timezone, language & location
185185
# Once page opens, click the "my location" button to see geolocation in action
186-
$ python -m playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com
186+
$ playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com
187187
```
188188

189189
## Inspect selectors
@@ -238,7 +238,7 @@ $ npx playwright screenshot --help
238238

239239
```sh python
240240
# See command help
241-
$ python -m playwright screenshot --help
241+
$ playwright screenshot --help
242242
```
243243

244244
```sh js
@@ -253,7 +253,7 @@ $ npx playwright \
253253

254254
```sh python
255255
# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)
256-
$ python -m playwright \
256+
$ playwright \
257257
--device="iPhone 11" \
258258
--color-scheme=dark \
259259
screenshot \
@@ -268,7 +268,7 @@ $ npx playwright screenshot --full-page en.wikipedia.org wiki-full.png
268268

269269
```sh python
270270
# Capture a full page screenshot
271-
$ python -m playwright screenshot --full-page en.wikipedia.org wiki-full.png
271+
$ playwright screenshot --full-page en.wikipedia.org wiki-full.png
272272
```
273273

274274
## Generate PDF
@@ -282,7 +282,7 @@ $ npx playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
282282

283283
```sh python
284284
# See command help
285-
$ python -m playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
285+
$ playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
286286
```
287287

288288
## Known limitations

docs/src/debug.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ for browser automation.
99

1010
<!-- TOC -->
1111

12+
## Playwright Inspector
13+
14+
[Playwright Inspector](./inspector.md) is a GUI tool that helps authoring and debugging Playwright scripts. That's our default recommended tool for scripts troubleshooting.
15+
16+
<img width="712" alt="Playwright Inspector" src="https://user-images.githubusercontent.com/883973/108614092-8c478a80-73ac-11eb-9597-67dfce110e00.png">
17+
18+
1219
## Run in headful mode
1320

1421
Playwright runs browsers in headless mode by default. To change this behavior,
@@ -42,9 +49,6 @@ breakpoints.
4249

4350
### Use the new JavaScript debugging terminal
4451

45-
VS Code 1.46+ introduced the new JavaScript debugger that does not require a `launch.json`
46-
configuration. To use it:
47-
4852
1. Set a breakpoint in VS Code
4953
* Use the `debugger` keyword or set a breakpoint in the VS Code UI
5054
1. Run your Node.js script from the terminal
@@ -109,8 +113,6 @@ With PWDEBUG, the following defaults are configured for you:
109113

110114
* **Run in headful**: With PWDEBUG, browsers always launch in headful mode
111115
* **Disables timeout**: PWDEBUG sets timeout to 0 (= no timeout)
112-
* **Preserve DevTools preferences**: When used with `devtools: true`, PWDEBUG
113-
preserves the docked/undocked state of Chrome DevTools
114116

115117
### Debugging Selectors
116118

docs/src/inspector.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
id: inspector
3+
title: "Inspector"
4+
---
5+
6+
Playwright Inspector is a GUI tool that helps authoring and debugging Playwright scripts.
7+
8+
<img width="712" alt="Playwright Inspector" src="https://user-images.githubusercontent.com/883973/108614092-8c478a80-73ac-11eb-9597-67dfce110e00.png">
9+
10+
<!-- TOC -->
11+
12+
## Open Playwright Inspector
13+
14+
There are several ways of opening Playwright Inspector:
15+
16+
- Set the `PWDEBUG` environment variable to run your scripts in debug mode. This
17+
configures Playwright for debugging and opens the inspector.
18+
```sh js
19+
# Linux/macOS
20+
$ PWDEBUG=1 npm run test
21+
22+
# Windows
23+
$ set PWDEBUG=1
24+
$ npm run test
25+
```
26+
27+
```sh python
28+
# Linux/macOS
29+
$ PWDEBUG=1 pytest -s
30+
31+
# Windows
32+
$ set PWDEBUG=1
33+
$ pytest -s
34+
```
35+
36+
Additional useful defaults are configured when `PWDEBUG` is set:
37+
- Browsers launch in the headed mode
38+
- Default timeout is set to 0 (= no timeout)
39+
40+
- Call [`method: Page.pause`] method from your script when running in headed browser.
41+
42+
```js
43+
// Pause on the following line.
44+
await page.pause();
45+
```
46+
47+
```python async
48+
# Pause on the following line.
49+
await page.pause()
50+
```
51+
52+
```python sync
53+
# Pause on the following line.
54+
page.pause()
55+
```
56+
57+
- Use `open` or `codegen` commands in the Playwright [CLI](./cli.md):
58+
```sh js
59+
$ npx playwright codegen wikipedia.org
60+
```
61+
62+
```sh python
63+
$ playwright codegen wikipedia.org
64+
```
65+
66+
## Stepping through the Playwright script
67+
68+
When `PWDEBUG` is set, Playwright Inspector window will be opened and the script will be
69+
paused on the first Playwright statement:
70+
71+
<img width="557" alt="Paused on line" src="https://user-images.githubusercontent.com/883973/108614337-71761580-73ae-11eb-9f61-3d29c52c9520.png">
72+
73+
Now we know what action is about to be performed and we can look into the details on that
74+
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:
75+
76+
<img width="344" alt="Red dot on inspected page" src="https://user-images.githubusercontent.com/883973/108614363-b69a4780-73ae-11eb-8f5e-51f9c91ec9b4.png">
77+
78+
By the time Playwright has paused on that click action, it has already performed actionability checks that can be found in the log:
79+
80+
<img width="712" alt="Action log" src="https://user-images.githubusercontent.com/883973/108614564-72a84200-73b0-11eb-9de2-828b28d78b36.png">
81+
82+
If actionability can't be reached, it'll show action as pending:
83+
84+
<img width="712" alt="Screen Shot 2021-02-20 at 7 36 06 PM" src="https://user-images.githubusercontent.com/883973/108614840-e6e3e500-73b2-11eb-998f-0cf31b2aa9a2.png">
85+
86+
You can step over each action using the "Step over" action or resume script without further pauses:
87+
88+
<center><img width="98" alt="Stepping toolbar" src="https://user-images.githubusercontent.com/883973/108614389-f9f4b600-73ae-11eb-8df2-8d9ce9da5d5c.png"></center>
89+
90+
91+
## Debugging Selectors
92+
93+
- Click the Explore button to hover over elements in the screen and click them to
94+
automatically generate selectors for those elements.
95+
- To verify where selector points, paste it into the inspector input field:
96+
97+
<img width="602" alt="Screen Shot 2021-02-20 at 7 27 20 PM" src="https://user-images.githubusercontent.com/883973/108614696-ad5eaa00-73b1-11eb-81f5-9eebe62543a2.png">
98+
99+
## Recording scripts
100+
101+
At any moment, clicking Record action enables recorder (codegen) mode.
102+
Every action on the target page is turned into the generated script:
103+
104+
<img width="712" alt="Screen Shot 2021-02-20 at 7 40 02 PM" src="https://user-images.githubusercontent.com/883973/108614897-85704600-73b3-11eb-8bcd-f2e129786c49.png">
105+
106+
You can copy entire generated script or clear it using toolbar actions.

docs/src/installation-python.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Each version of Playwright needs specific versions of browser binaries to operat
1515

1616
```sh
1717
$ pip install playwright
18-
$ python -m playwright install
18+
$ playwright install
1919
```
2020

2121
These browsers will take few hundreds of megabytes of the disk space when installed:
@@ -37,7 +37,7 @@ $ PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers python -m playwright install
3737
# Windows
3838
$ set PLAYWRIGHT_BROWSERS_PATH=%USERPROFILE%\pw-browsers
3939
$ pip install playwright
40-
$ python -m playwright install
40+
$ playwright install
4141
```
4242

4343
When running Playwright scripts, ask it to search for browsers in a shared location:
@@ -61,7 +61,7 @@ $ PLAYWRIGHT_BROWSERS_PATH=0 python -m playwright install
6161
# Windows
6262
$ set PLAYWRIGHT_BROWSERS_PATH=0
6363
$ pip install playwright
64-
$ python -m playwright install
64+
$ playwright install
6565
```
6666

6767
Playwright keeps track of packages that need those browsers and will garbage collect them as you update Playwright to the newer versions.
@@ -86,7 +86,7 @@ $ PLAYWRIGHT_DOWNLOAD_HOST=192.168.1.78 python -m playwright install
8686
# Windows
8787
$ set PLAYWRIGHT_DOWNLOAD_HOST=192.168.1.78
8888
$ pip install playwright
89-
$ python -m playwright install
89+
$ playwright install
9090
```
9191

9292
It is also possible to use a per-browser download hosts using `PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST`, `PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST` and `PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST` env variables that
@@ -113,7 +113,7 @@ $ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 python -m playwright install
113113
# Windows
114114
$ set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
115115
$ pip install playwright
116-
$ python -m playwright install
116+
$ playwright install
117117
```
118118

119119
## Download single browser binary
@@ -122,5 +122,5 @@ Playwright downloads Chromium, Firefox and WebKit browsers by default. To instal
122122

123123
```sh
124124
$ pip install playwright
125-
$ python -m playwright install firefox
125+
$ playwright install firefox
126126
```

docs/src/intro-python.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Use pip to install Playwright in your Python project. See [system requirements](
1212

1313
```sh
1414
$ pip install playwright
15-
$ python -m playwright install
15+
$ playwright install
1616
```
1717

1818
These commands download the Playwright package and install browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./installation.md).
@@ -75,7 +75,7 @@ firefox.launch(headless=False, slowMo=50)
7575
Command Line Interface [CLI](./cli.md) can be used to record user interactions and generate Python code.
7676

7777
```sh
78-
$ python -m playwright codegen wikipedia.org
78+
$ playwright codegen wikipedia.org
7979
```
8080

8181
## System requirements

docs/src/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ title: "Release notes"
1313
$ npx playwright --help
1414
```
1515
```sh python
16-
$ python -m playwright --help
16+
$ playwright --help
1717
```
1818
- [`method: Page.selectOption`] now waits for the options to be present.
1919
- New methods to [assert element state](./actionability#assertions) like [`method: Page.isEditable`].

docs/src/why-playwright.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Playwright enables fast, reliable and capable automation across all modern brows
4242
```
4343
```sh python
4444
$ pip install playwright
45-
$ python -m playwright install
45+
$ playwright install
4646
```
4747

4848
* **TypeScript support**. Playwright ships with built-in types for auto-completion and other benefits.

utils/markdown.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ function buildTree(lines) {
125125
};
126126
line = lines[++i];
127127
while (!line.trim().startsWith('```')) {
128-
if (!line.startsWith(indent)) {
128+
if (line && !line.startsWith(indent)) {
129129
const from = Math.max(0, i - 5)
130130
const to = Math.min(lines.length, from + 10);
131131
const snippet = lines.slice(from, to);
132132
throw new Error(`Bad code block: ${snippet.join('\n')}`);
133133
}
134-
node.lines.push(line.substring(indent.length));
134+
if (line)
135+
line = line.substring(indent.length);
136+
node.lines.push(line);
135137
line = lines[++i];
136138
}
137139
appendNode(indent, node);

0 commit comments

Comments
 (0)