Skip to content

Commit 4e33ade

Browse files
authored
docs: fix codegen --viewport option examples (#33816)
1 parent b456ac5 commit 4e33ade

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

docs/src/codegen.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Install the VS Code extension and generate tests directly from VS Code. The exte
2121

2222
### Record a New Test
2323

24-
To record a test click on the **Record new** button from the Testing sidebar. This will create a `test-1.spec.ts` file as well as open up a browser window.
24+
To record a test click on the **Record new** button from the Testing sidebar. This will create a `test-1.spec.ts` file as well as open up a browser window.
2525

2626
<img width="1385" alt="record new in vs code" src="https://user-images.githubusercontent.com/13063165/220961665-615d0ab8-3f0b-439c-ad0b-0424d9aa154b.png" />
2727

@@ -58,16 +58,16 @@ In the test file in VS Code you will see your new generated actions added to you
5858

5959
### Generating locators
6060

61-
You can generate locators with the test generator.
62-
- Click on the **Pick locator** button form the testing sidebar and then hover over elements in the browser window to see the [locator](./locators.md) highlighted underneath each element.
63-
- Click the element you require and it will now show up in the **Pick locator** box in VS Code.
61+
You can generate locators with the test generator.
62+
- Click on the **Pick locator** button form the testing sidebar and then hover over elements in the browser window to see the [locator](./locators.md) highlighted underneath each element.
63+
- Click the element you require and it will now show up in the **Pick locator** box in VS Code.
6464
- Press <kbd>Enter</kbd> on your keyboard to copy the locator into the clipboard and then paste anywhere in your code. Or press 'escape' if you want to cancel.
6565

6666
<img width="1641" alt="Pick locators in VS code" src="https://user-images.githubusercontent.com/13063165/220958368-95b03620-3c9b-40a8-be74-01c96ba03cad.png" />
6767

6868
## Generate tests with the Playwright Inspector
6969

70-
When running the `codegen` command two windows will be opened, a browser window where you interact with the website you wish to test and the Playwright Inspector window where you can record your tests and then copy them into your editor.
70+
When running the `codegen` command two windows will be opened, a browser window where you interact with the website you wish to test and the Playwright Inspector window where you can record your tests and then copy them into your editor.
7171

7272
### Running Codegen
7373

@@ -128,10 +128,10 @@ When you have finished interacting with the page, press the **record** button to
128128
Use the **clear** button to clear the code to start recording again. Once finished, close the Playwright inspector window or stop the terminal command.
129129

130130
### Generating locators
131-
You can generate [locators](/locators.md) with the test generator.
131+
You can generate [locators](/locators.md) with the test generator.
132132

133133
* Press the `'Record'` button to stop the recording and the `'Pick Locator'` button will appear.
134-
* Click on the `'Pick Locator'` button and then hover over elements in the browser window to see the locator highlighted underneath each element.
134+
* Click on the `'Pick Locator'` button and then hover over elements in the browser window to see the locator highlighted underneath each element.
135135
* To choose a locator, click on the element you would like to locate and the code for that locator will appear in the field next to the Pick Locator button.
136136
* You can then edit the locator in this field to fine tune it or use the copy button to copy it and paste it into your code.
137137

@@ -164,19 +164,19 @@ You can use the test generator to generate tests using emulation so as to genera
164164
Playwright opens a browser window with its 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.
165165

166166
```bash js
167-
npx playwright codegen --viewport-size=800,600 playwright.dev
167+
npx playwright codegen --viewport-size="800,600" playwright.dev
168168
```
169169

170170
```bash java
171-
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen --viewport-size=800,600 playwright.dev"
171+
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen --viewport-size='800,600' playwright.dev"
172172
```
173173

174174
```bash python
175-
playwright codegen --viewport-size=800,600 playwright.dev
175+
playwright codegen --viewport-size="800,600" playwright.dev
176176
```
177177

178178
```bash csharp
179-
pwsh bin/Debug/netX/playwright.ps1 codegen --viewport-size=800,600 playwright.dev
179+
pwsh bin/Debug/netX/playwright.ps1 codegen --viewport-size="800,600" playwright.dev
180180
```
181181
######
182182
* langs: js
@@ -325,7 +325,7 @@ pwsh bin/Debug/netX/playwright.ps1 codegen --timezone="Europe/Rome" --geolocatio
325325

326326
### Preserve authenticated state
327327

328-
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 when recording more tests.
328+
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 when recording more tests.
329329

330330
```bash js
331331
npx playwright codegen github.com/microsoft/playwright --save-storage=auth.json
@@ -367,7 +367,7 @@ pwsh bin/Debug/netX/playwright.ps1 codegen github.com/microsoft/playwright --sav
367367

368368
#### Login
369369

370-
After performing authentication and closing the browser, `auth.json` will contain the storage state which you can then reuse in your tests.
370+
After performing authentication and closing the browser, `auth.json` will contain the storage state which you can then reuse in your tests.
371371

372372
<img width="1394" alt="login to GitHub screen" src="https://user-images.githubusercontent.com/13063165/220561688-04b2b984-4ba6-4446-8b0a-8058876e2a02.png" />
373373

packages/playwright-core/src/cli/program.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,12 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro
449449
// Viewport size
450450
if (options.viewportSize) {
451451
try {
452-
const [width, height] = options.viewportSize.split(',').map(n => parseInt(n, 10));
452+
const [width, height] = options.viewportSize.split(',').map(n => +n);
453+
if (isNaN(width) || isNaN(height))
454+
throw new Error('bad values');
453455
contextOptions.viewport = { width, height };
454456
} catch (e) {
455-
throw new Error('Invalid viewport size format: use "width, height", for example --viewport-size=800,600');
457+
throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
456458
}
457459
}
458460

0 commit comments

Comments
 (0)