Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(dot): onTestPause + make --pause private (#38904)
Simon Knott42b978447280
diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.tsindex bafd9ecc8d..82d88aafed 100644--- a/packages/playwright/src/common/config.ts+++ b/packages/playwright/src/common/config.ts@@ -118,7 +118,7 @@ export class FullConfigInternal {updateSnapshots: takeFirst(configCLIOverrides.updateSnapshots, userConfig.updateSnapshots, 'missing'),updateSourceMethod: takeFirst(configCLIOverrides.updateSourceMethod, userConfig.updateSourceMethod, 'patch'),version: require('../../package.json').version,- workers: resolveWorkers(takeFirst(configCLIOverrides.pause ? 1 : undefined, configCLIOverrides.workers, userConfig.workers, '50%')),+ workers: resolveWorkers(takeFirst((configCLIOverrides.debug || configCLIOverrides.pause) ? 1 : undefined, configCLIOverrides.workers, userConfig.workers, '50%')),webServer: null,};for (const key in userConfig) {diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.tsindex 0df97a777c..d2f52d3b8d 100644--- a/packages/playwright/src/program.ts+++ b/packages/playwright/src/program.ts@@ -308,7 +308,7 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverridupdateSourceMethod: options.updateSourceMethod,runAgents: options.runAgents,workers: options.workers,- pause: options.pause ? true : undefined,+ pause: process.env.PWPAUSE ? true : undefined,};if (options.browser) {@@ -328,7 +328,6 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverridoverrides.use = { headless: false };if (!options.ui && options.debug) {overrides.debug = true;- overrides.pause = true;process.env.PWDEBUG = '1';}if (!options.ui && options.trace) {@@ -403,7 +402,7 @@ const kTraceModes: TraceMode[] = ['on', 'off', 'on-first-retry', 'on-all-retriesconst testOptions: [string, { description: string, choices?: string[], preset?: string }][] = [/* deprecated */ ['--browser <browser>', { description: `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")` }],['-c, --config <file>', { description: `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"` }],- ['--debug', { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1 --pause" options` }],+ ['--debug', { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options` }],['--fail-on-flaky-tests', { description: `Fail if any test is flagged as flaky (default: false)` }],['--forbid-only', { description: `Fail if test.only is called (default: false)` }],['--fully-parallel', { description: `Run all tests in parallel (default: false)` }],@@ -419,7 +418,6 @@ const testOptions: [string, { description: string, choices?: string[], preset?:['--output <dir>', { description: `Folder for output artifacts (default: "test-results")` }],['--only-changed [ref]', { description: `Only run test files that have been changed between 'HEAD' and 'ref'. Defaults to running all uncommitted changes. Only supports Git.` }],['--pass-with-no-tests', { description: `Makes test run succeed even if no tests were found` }],- ['--pause', { description: `Run tests in headed mode and pause at the end of test execution` }],['--project <project-name...>', { description: `Only run tests from the specified list of projects, supports '*' wildcard (default: run all projects)` }],['--quiet', { description: `Suppress stdio` }],['--repeat-each <N>', { description: `Run each test N times (default: 1)` }],diff --git a/packages/playwright/src/reporters/dot.ts b/packages/playwright/src/reporters/dot.tsindex c2076147db..723ee6ad93 100644--- a/packages/playwright/src/reporters/dot.ts+++ b/packages/playwright/src/reporters/dot.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { TerminalReporter } from './base';+import { markErrorsAsReported, TerminalReporter } from './base';import type { FullResult, Suite, TestCase, TestError, TestResult } from '../../types/testReporter';@@ -66,6 +66,26 @@ class DotReporter extends TerminalReporter {this._counter = 0;}+ async onTestPaused(test: TestCase, result: TestResult) {+ // Without TTY, user cannot interrupt the pause. Let's skip it.+ if (!process.stdin.isTTY && !process.env.PW_TEST_DEBUG_REPORTERS)+ return;++ this.screen.stdout.write('\n');+ if (test.outcome() === 'unexpected') {+ this.writeLine(this.screen.colors.red(this.formatTestHeader(test, { indent: ' ' })));+ this.writeLine(this.formatResultErrors(test, result));+ markErrorsAsReported(result);+ this.writeLine(this.screen.colors.yellow(' Paused on error. Press Ctrl+C to end.') + '\n');+ } else {+ this.writeLine(this.screen.colors.yellow(this.formatTestHeader(test, { indent: ' ' })));+ this.writeLine(this.screen.colors.yellow(' Paused at test end. Press Ctrl+C to end.') + '\n');+ }+ this._counter = 0;++ await new Promise<void>(() => {});+ }+override async onEnd(result: FullResult) {await super.onEnd(result);this.screen.stdout.write('\n');diff --git a/tests/playwright-test/pause-at-end.spec.ts b/tests/playwright-test/pause-at-end.spec.tsindex 60f2775864..0aa640cbed 100644--- a/tests/playwright-test/pause-at-end.spec.ts+++ b/tests/playwright-test/pause-at-end.spec.ts@@ -65,7 +65,7 @@ class LocationReporter implements ReporterV2 {}}-test('--debug should pause at end', async ({ runInlineTest }) => {+test('--pause should pause at end', async ({ runInlineTest }) => {const result = await runInlineTest({'location-reporter.js': `export default ${LocationReporter}`,'playwright.config.js': `@@ -79,7 +79,7 @@ test('--debug should pause at end', async ({ runInlineTest }) => {console.log('%%teardown');});`- }, { pause: true });+ }, {}, { PWPAUSE: '1' });expect(result.outputLines).toEqual(['onTestPaused at end','teardown',@@ -87,7 +87,7 @@ test('--debug should pause at end', async ({ runInlineTest }) => {]);});-test('--debug should pause at end with setup project', async ({ runInlineTest }) => {+test('--pause should pause at end with setup project', async ({ runInlineTest }) => {const result = await runInlineTest({'location-reporter.js': `export default ${LocationReporter}`,'playwright.config.js': `@@ -110,11 +110,11 @@ test('--debug should pause at end with setup project', async ({ runInlineTest })console.log('main test started');});`- }, { pause: true });+ }, {}, { PWPAUSE: '1' });expect(result.outputLines).toContain('onTestPaused at end');});-test('--debug should pause on error', async ({ runInlineTest, mergeReports }) => {+test('--pause should pause on error', async ({ runInlineTest, mergeReports }) => {const result = await runInlineTest({'location-reporter.js': `export default ${LocationReporter}`,'playwright.config.js': `@@ -128,7 +128,7 @@ test('--debug should pause on error', async ({ runInlineTest, mergeReports }) =>console.log('%%after error');});`- }, { pause: true });+ }, {}, { PWPAUSE: '1' });expect(result.outputLines).toEqual(['onTestPaused on error at :4:24','result.errors[0] at :4:24',@@ -159,7 +159,7 @@ test('SIGINT after pause at end should still run teardown', async ({ runInlineTeconsole.log('%%teardown');});`- }, { pause: true }, { SIGINT_AFTER_PAUSE: '1' });+ }, {}, { PWPAUSE: '1', SIGINT_AFTER_PAUSE: '1' });expect(result.outputLines).toEqual(['onTestPaused at end','SIGINT',@@ -185,7 +185,7 @@ test('SIGINT after pause on error should still run teardown', async ({ runInlineconsole.log('%%teardown');});`- }, { pause: true }, { SIGINT_AFTER_PAUSE: '1' });+ }, {}, { PWPAUSE: '1', SIGINT_AFTER_PAUSE: '1' });expect(result.outputLines).toEqual(['onTestPaused on error at :4:19','result.errors[0] at :4:19',diff --git a/tests/playwright-test/reporter-line.spec.ts b/tests/playwright-test/reporter-line.spec.tsindex 43c42c7081..f999b39918 100644--- a/tests/playwright-test/reporter-line.spec.ts+++ b/tests/playwright-test/reporter-line.spec.ts@@ -240,7 +240,7 @@ test.describe('onTestPaused', () => {console.log('Running teardown');});`,- }, { pause: true, reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused at test end. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');@@ -279,7 +279,7 @@ Running teardownthrow new Error('teardown error');});`,- }, { pause: true, reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused at test end. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');@@ -323,7 +323,7 @@ Running 1 test using 1 workerexpect(3).toBe(4);});`,- }, { pause: true, reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'line' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused on error. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');diff --git a/tests/playwright-test/reporter-list.spec.ts b/tests/playwright-test/reporter-list.spec.tsindex 7d2a87f160..c48893d9e7 100644--- a/tests/playwright-test/reporter-list.spec.ts+++ b/tests/playwright-test/reporter-list.spec.ts@@ -430,7 +430,7 @@ test.describe('onTestPaused', () => {console.log('Running teardown');});`,- }, { pause: true, reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused at test end. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');@@ -460,7 +460,7 @@ Running teardownthrow new Error('teardown error');});`,- }, { pause: true, reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused at test end. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');@@ -502,7 +502,7 @@ Running 1 test using 1 workerexpect(3).toBe(4);});`,- }, { pause: true, reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1' });+ }, { reporter: 'list' }, { PW_TEST_DEBUG_REPORTERS: '1', PWPAUSE: '1' });await runner.waitForOutput('Paused on error. Press Ctrl+C to end.');const { exitCode } = await runner.kill('SIGINT');