From a9238ce2e1e71350ef329923443c71d87ddd5c6b Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 3 Mar 2021 22:25:14 -0800 Subject: [PATCH] feat(debug): introduce npx playwright debug (#5679) --- docs/src/cli.md | 38 +++-- src/cli/cli.ts | 173 ++++++++++++---------- test/cli/cli-codegen-csharp.spec.ts | 8 +- test/cli/cli-codegen-java.spec.ts | 8 +- test/cli/cli-codegen-javascript.spec.ts | 8 +- test/cli/cli-codegen-python-async.spec.ts | 8 +- test/cli/cli-codegen-python.spec.ts | 8 +- test/cli/cli.fixtures.ts | 2 +- 8 files changed, 134 insertions(+), 119 deletions(-) diff --git a/docs/src/cli.md b/docs/src/cli.md index 9b8fce65d8..763b33fa89 100644 --- a/docs/src/cli.md +++ b/docs/src/cli.md @@ -45,13 +45,13 @@ Run `codegen` and perform actions in the browser. Playwright CLI will generate J 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. ```sh js -$ npx playwright --save-storage=auth.json codegen +$ npx playwright codegen --save-storage=auth.json # Perform authentication and exit. # auth.json will contain the storage state. ``` ```sh python -$ playwright --save-storage=auth.json codegen +$ playwright codegen --save-storage=auth.json # Perform authentication and exit. # auth.json will contain the storage state. ``` @@ -59,14 +59,14 @@ $ playwright --save-storage=auth.json codegen 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. ```sh js -$ npx playwright --load-storage=auth.json open my.web.app -$ npx playwright --load-storage=auth.json codegen my.web.app +$ npx playwright open --load-storage=auth.json my.web.app +$ npx playwright codegen --load-storage=auth.json my.web.app # Perform actions in authenticated state. ``` ```sh python -$ playwright --load-storage=auth.json open my.web.app -$ playwright --load-storage=auth.json codegen my.web.app +$ playwright open --load-storage=auth.json my.web.app +$ playwright codegen --load-storage=auth.json my.web.app # Perform actions in authenticated state. ``` @@ -177,34 +177,34 @@ $ playwright wk example.com ```sh js # Emulate iPhone 11. -$ npx playwright --device="iPhone 11" open wikipedia.org +$ npx playwright open --device="iPhone 11" wikipedia.org ``` ```sh python # Emulate iPhone 11. -$ playwright --device="iPhone 11" open wikipedia.org +$ playwright open --device="iPhone 11" wikipedia.org ``` ### Emulate color scheme and viewport size ```sh js # Emulate screen size and color scheme. -$ npx playwright --viewport-size=800,600 --color-scheme=dark open twitter.com +$ npx playwright open --viewport-size=800,600 --color-scheme=dark twitter.com ``` ```sh python # Emulate screen size and color scheme. -$ playwright --viewport-size=800,600 --color-scheme=dark open twitter.com +$ playwright open --viewport-size=800,600 --color-scheme=dark twitter.com ``` ### Emulate geolocation, language and timezone ```sh js # Emulate timezone, language & location # Once page opens, click the "my location" button to see geolocation in action -$ npx playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com +$ npx playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com ``` ```sh python # Emulate timezone, language & location # Once page opens, click the "my location" button to see geolocation in action -$ playwright --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" open maps.google.com +$ playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com ``` ## Inspect selectors @@ -264,20 +264,18 @@ $ playwright screenshot --help ```sh js # Wait 3 seconds before capturing a screenshot after page loads ('load' event fires) -$ npx playwright \ - --device="iPhone 11" \ - --color-scheme=dark \ - screenshot \ +$ npx playwright screenshot \ + --device="iPhone 11" \ + --color-scheme=dark \ --wait-for-timeout=3000 \ twitter.com twitter-iphone.png ``` ```sh python # Wait 3 seconds before capturing a screenshot after page loads ('load' event fires) -$ playwright \ - --device="iPhone 11" \ - --color-scheme=dark \ - screenshot \ +$ playwright screenshot \ + --device="iPhone 11" \ + --color-scheme=dark \ --wait-for-timeout=3000 \ twitter.com twitter-iphone.png ``` diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 0889d6844e..cab82d35d0 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -30,105 +30,58 @@ import { Browser } from '../client/browser'; import { Page } from '../client/page'; import { BrowserType } from '../client/browserType'; import { BrowserContextOptions, LaunchOptions } from '../client/types'; +import { spawn } from 'child_process'; program .version('Version ' + require('../../package.json').version) - .name('npx playwright') - .option('-b, --browser ', 'browser to use, one of cr, chromium, ff, firefox, wk, webkit', 'chromium') - .option('--color-scheme ', 'emulate preferred color scheme, "light" or "dark"') - .option('--device ', 'emulate device, for example "iPhone 11"') - .option('--geolocation ', 'specify geolocation coordinates, for example "37.819722,-122.478611"') - .option('--lang ', 'specify language / locale, for example "en-GB"') - .option('--load-storage ', 'load context storage state from the file, previously saved with --save-storage') - .option('--proxy-server ', 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"') - .option('--save-storage ', 'save context storage state at the end, for later use with --load-storage') - .option('--timezone