docs: fix codegen --viewport option examples (#33816)
This commit is contained in:
parent
b456ac5f8c
commit
4e33ade287
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue