From 131239569d5652274560d578d3696d4002a70d42 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 15 Sep 2021 21:19:31 +0200 Subject: [PATCH] feat(test-runner): add --debug CLI flag (#8938) --- docs/src/intro-js.md | 11 +---------- docs/src/test-cli-js.md | 13 +++---------- src/test/cli.ts | 9 ++++++++- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/docs/src/intro-js.md b/docs/src/intro-js.md index c82f9b64d7..236103128f 100644 --- a/docs/src/intro-js.md +++ b/docs/src/intro-js.md @@ -285,16 +285,7 @@ Following are the usual command line patterns. Learn more about the [command lin - Run in debug mode with [Playwright Inspector](./inspector.md) ```bash - # Linux/macOS - PWDEBUG=1 npx playwright test - - # Windows with cmd.exe - set PWDEBUG=1 - npx playwright test - - # Windows with PowerShell - $env:PWDEBUG=1 - npx playwright test + npx playwright test --debug ``` - Ask for help diff --git a/docs/src/test-cli-js.md b/docs/src/test-cli-js.md index 8f83014435..1fb96cd9c0 100644 --- a/docs/src/test-cli-js.md +++ b/docs/src/test-cli-js.md @@ -61,16 +61,7 @@ Here are the most common options available in the command line. - Run in debug mode with [Playwright Inspector](./inspector.md) ```bash - # Linux/macOS - PWDEBUG=1 npx playwright test - - # Windows with cmd.exe - set PWDEBUG=1 - npx playwright test - - # Windows with PowerShell - $env:PWDEBUG=1 - npx playwright test + npx playwright test --debug ``` - Ask for help @@ -86,6 +77,8 @@ Complete set of Playwright Test options is available in the [configuration file] - `--browser`: Run test in a specific browser. Available options are `"chromium"`, `"firefox"`, `"webkit"` or `"all"` to run tests in all three browsers at the same time. +- `--debug`: Run tests with Playwright Inspector. Shortcut for `PWDEBUG=1` environment variable and `--timeout=0 --maxFailures=1 --headed --workers=1` options + - `-c ` or `--config `: Configuration file. If not passed, defaults to `playwright.config.ts` or `playwright.config.js` in the current directory. - `-c ` or `--config `: Directory with the tests to run without configuration file. diff --git a/src/test/cli.ts b/src/test/cli.ts index d3264a7d12..f4cacdb5db 100644 --- a/src/test/cli.ts +++ b/src/test/cli.ts @@ -44,6 +44,7 @@ export function addTestCommand(program: commander.CommanderStatic) { command.description('Run tests with Playwright Test'); command.option('--browser ', `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")`); command.option('--headed', `Run tests in headed browsers (default: headless)`); + command.option('--debug', `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --maxFailures=1 --headed --workers=1" options`); command.option('-c, --config ', `Configuration file, or a test directory with optional "${tsConfig}"/"${jsConfig}"`); command.option('--forbid-only', `Fail if test.only is called (default: false)`); command.option('-g, --grep ', `Only run tests matching this regular expression (default: ".*")`); @@ -97,8 +98,14 @@ async function createLoader(opts: { [key: string]: any }): Promise { } const overrides = overridesFromOptions(opts); - if (opts.headed) + if (opts.headed || opts.debug) overrides.use = { headless: false }; + if (opts.debug) { + overrides.maxFailures = 1; + overrides.timeout = 0; + overrides.workers = 1; + process.env.PWDEBUG = '1'; + } const loader = new Loader(defaultConfig, overrides); async function loadConfig(configFile: string) {