Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: make sure browser crashes in CLI tests are marked as such (#15821)

Dmitry Gozmanba3c8ffa5cfb
diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts
index aaf8bb27e7..b5a4cc7320 100755
--- a/packages/playwright-core/src/cli/cli.ts
+++ b/packages/playwright-core/src/cli/cli.ts
@@ -410,6 +410,23 @@ async function launchContext(options: Options, headless: boolean, executablePath
const browser = await browserType.launch(launchOptions);
+ if (process.env.PWTEST_CLI_EXIT) {
+ const logs: string[] = [];
+ require('playwright-core/lib/utilsBundle').debug.log = (...args: any[]) => {
+ const line = require('util').format(...args) + '\n';
+ logs.push(line);
+ process.stderr.write(line);
+ };
+ browser.on('disconnected', () => {
+ const hasCrashLine = logs.some(line => line.includes('process did exit:') && !line.includes('process did exit: exitCode=0, signal=null'));
+ if (hasCrashLine) {
+ process.stderr.write('Detected browser crash.\n');
+ // Make sure we exit abnormally when browser crashes.
+ process.exit(1);
+ }
+ });
+ }
+
// Viewport size
if (options.viewportSize) {
try {
diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.ts
index 2771c6d492..a422e866f9 100644
--- a/tests/library/inspector/inspectorTest.ts
+++ b/tests/library/inspector/inspectorTest.ts
@@ -60,7 +60,7 @@ export const test = contextTest.extend<CLITestArgs>({
return cli;
});
if (cli)
- await cli.exited;
+ await cli.exited.catch(() => {});
},
openRecorder: async ({ page, recorderPageGetter }, run) => {
@@ -199,6 +199,7 @@ class CLIMock {
PWTEST_CLI_EXIT: '1',
PWTEST_CLI_HEADLESS: headless ? '1' : undefined,
PWTEST_CLI_EXECUTABLE_PATH: executablePath,
+ DEBUG: (process.env.DEBUG ?? '') + ',pw:browser*',
},
});
this.process.onOutput = () => {