docs: fix codegen --viewport option examples (#33816)

This commit is contained in:
Dmitry Gozman 2024-11-29 14:13:53 +00:00 committed by GitHub
parent b456ac5f8c
commit 4e33ade287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 15 deletions

View file

@ -164,19 +164,19 @@ You can use the test generator to generate tests using emulation so as to genera
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.
```bash js
npx playwright codegen --viewport-size=800,600 playwright.dev
npx playwright codegen --viewport-size="800,600" playwright.dev
```
```bash java
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen --viewport-size=800,600 playwright.dev"
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen --viewport-size='800,600' playwright.dev"
```
```bash python
playwright codegen --viewport-size=800,600 playwright.dev
playwright codegen --viewport-size="800,600" playwright.dev
```
```bash csharp
pwsh bin/Debug/netX/playwright.ps1 codegen --viewport-size=800,600 playwright.dev
pwsh bin/Debug/netX/playwright.ps1 codegen --viewport-size="800,600" playwright.dev
```
######
* langs: js

View file

@ -449,10 +449,12 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro
// Viewport size
if (options.viewportSize) {
try {
const [width, height] = options.viewportSize.split(',').map(n => parseInt(n, 10));
const [width, height] = options.viewportSize.split(',').map(n => +n);
if (isNaN(width) || isNaN(height))
throw new Error('bad values');
contextOptions.viewport = { width, height };
} catch (e) {
throw new Error('Invalid viewport size format: use "width, height", for example --viewport-size=800,600');
throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
}
}