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.
|
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
|
```bash js
|
||||||
npx playwright codegen --viewport-size=800,600 playwright.dev
|
npx playwright codegen --viewport-size="800,600" playwright.dev
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash java
|
```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
|
```bash python
|
||||||
playwright codegen --viewport-size=800,600 playwright.dev
|
playwright codegen --viewport-size="800,600" playwright.dev
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash csharp
|
```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
|
* langs: js
|
||||||
|
|
|
||||||
|
|
@ -449,10 +449,12 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro
|
||||||
// Viewport size
|
// Viewport size
|
||||||
if (options.viewportSize) {
|
if (options.viewportSize) {
|
||||||
try {
|
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 };
|
contextOptions.viewport = { width, height };
|
||||||
} catch (e) {
|
} 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