You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/cli.md
+89-20Lines changed: 89 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,14 @@ Playwright comes with the command line tools that run via `npx` or as a part of
9
9
10
10
## Usage
11
11
12
-
```sh
12
+
```sh js
13
13
$ npx playwright --help
14
14
```
15
15
16
+
```sh python
17
+
$ python -m playwright
18
+
```
19
+
16
20
Running from `package.json` script
17
21
```json
18
22
{
@@ -24,10 +28,14 @@ Running from `package.json` script
24
28
25
29
## Generate code
26
30
27
-
```sh
31
+
```sh js
28
32
$ npx playwright codegen wikipedia.org
29
33
```
30
34
35
+
```sh python
36
+
$ python -m playwright codegen wikipedia.org
37
+
```
38
+
31
39
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.
@@ -36,53 +44,89 @@ Run `codegen` and perform actions in the browser. Playwright CLI will generate J
36
44
37
45
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. This is useful to separately record authentication step and reuse it later.
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.
46
60
47
-
```sh
61
+
```sh js
48
62
$ npx playwright --load-storage=auth.json open my.web.app
With `open`, you can use Playwright bundled browsers to browse web pages. Playwright provides cross-platform WebKit builds that can be used to reproduce Safari rendering across Windows, Linux and macOS.
56
76
57
-
```sh
77
+
```sh js
58
78
# Open page in Chromium
59
-
npx playwright open example.com
79
+
$ npx playwright open example.com
60
80
```
61
81
62
-
```sh
82
+
```sh python
83
+
# Open page in Chromium
84
+
$ python -m playwright open example.com
85
+
```
86
+
87
+
```sh js
88
+
# Open page in WebKit
89
+
$ npx playwright wk example.com
90
+
```
91
+
92
+
```sh python
63
93
# Open page in WebKit
64
-
npx playwright wk example.com
94
+
$ python -m playwright wk example.com
65
95
```
66
96
67
97
### Emulate devices
68
98
`open` can emulate mobile and tablet devices ([see all devices](https://github.com/microsoft/playwright/blob/master/src/server/deviceDescriptors.ts)).
69
99
70
-
```sh
100
+
```sh js
71
101
# Emulate iPhone 11.
72
-
npx playwright --device="iPhone 11" open wikipedia.org
102
+
$ npx playwright --device="iPhone 11" open wikipedia.org
103
+
```
104
+
105
+
```sh python
106
+
# Emulate iPhone 11.
107
+
$ python -m playwright --device="iPhone 11" open wikipedia.org
73
108
```
74
109
75
110
### Emulate color scheme and viewport size
76
-
```sh
111
+
```sh js
112
+
# Emulate screen size and color scheme.
113
+
$ npx playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
114
+
```
115
+
```sh python
77
116
# Emulate screen size and color scheme.
78
-
npx playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
117
+
$ python -m playwright --viewport-size=800,600 --color-scheme=dark open twitter.com
79
118
```
80
119
81
120
### Emulate geolocation, language and timezone
82
-
```sh
121
+
```sh js
122
+
# Emulate timezone, language & location
123
+
# Once page opens, click the "my location" button to see geolocation in action
124
+
$ npx playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com
125
+
```
126
+
```sh python
83
127
# Emulate timezone, language & location
84
128
# Once page opens, click the "my location" button to see geolocation in action
85
-
npx playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com
129
+
$ python -m playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com
86
130
```
87
131
88
132
## Inspect selectors
@@ -130,34 +174,59 @@ Generates selector for the given element.
130
174
131
175
## Take screenshot
132
176
133
-
```sh
177
+
```sh js
134
178
# See command help
135
179
$ npx playwright screenshot --help
136
180
```
137
181
138
-
```sh
182
+
```sh python
183
+
# See command help
184
+
$ python -m playwright screenshot --help
185
+
```
186
+
187
+
```sh js
139
188
# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)
140
-
npx playwright \
189
+
$ npx playwright \
141
190
--device="iPhone 11" \
142
191
--color-scheme=dark \
143
192
screenshot \
144
193
--wait-for-timeout=3000 \
145
194
twitter.com twitter-iphone.png
146
195
```
147
196
148
-
```sh
197
+
```sh python
198
+
# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)
Copy file name to clipboardExpand all lines: docs/src/intro-python.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ title: "Getting Started"
10
10
Use pip to install Playwright in your Python project. See [system requirements](#system-requirements).
11
11
12
12
```sh
13
-
pip install playwright
14
-
python -m playwright install
13
+
$ pip install playwright
14
+
$ python -m playwright install
15
15
```
16
16
17
17
These commands download the Playwright package and install browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./installation.md).
Copy file name to clipboardExpand all lines: docs/src/intro.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ title: "Getting Started"
10
10
Use npm or Yarn to install Playwright in your Node.js project. See [system requirements](#system-requirements).
11
11
12
12
```sh
13
-
npm i -D playwright
13
+
$ npm i -D playwright
14
14
```
15
15
16
16
This single command downloads the Playwright NPM package and browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](./installation.md).
Copy file name to clipboardExpand all lines: docs/src/test-runners-python.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ in Python.
11
11
## Usage
12
12
13
13
```sh
14
-
pip install pytest-playwright
14
+
$ pip install pytest-playwright
15
15
```
16
16
17
17
Use the `page` fixture to write a basic test. See [more examples](#examples).
@@ -27,16 +27,16 @@ To run your tests, use pytest CLI.
27
27
28
28
```sh
29
29
# Run tests (Chromium and headless by default)
30
-
pytest
30
+
$ pytest
31
31
32
32
# Run tests in headful mode
33
-
pytest --headful
33
+
$ pytest --headful
34
34
35
35
# Run tests in a different browser (chromium, firefox, webkit)
36
-
pytest --browser firefox
36
+
$ pytest --browser firefox
37
37
38
38
# Run tests in multiple browsers
39
-
pytest --browser chromium --browser webkit
39
+
$ pytest --browser chromium --browser webkit
40
40
```
41
41
42
42
If you want to add the CLI arguments automatically without specifying them, you can use the [pytest.ini](https://docs.pytest.org/en/stable/reference.html#ini-options-ref) file:
0 commit comments