Skip to content

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

test(mcp): tear down daemons spawned via cli --json in fixture teardown (#40352)

Simon Knott47146f2b05f9
diff --git a/tests/mcp/cli-fixtures.ts b/tests/mcp/cli-fixtures.ts
index 2b578149c1..15a1487ea9 100644
--- a/tests/mcp/cli-fixtures.ts
+++ b/tests/mcp/cli-fixtures.ts
@@ -159,7 +159,7 @@ async function runCli(childProcess: CommonFixtures['childProcess'], args: string
const attachments = loadAttachments(cli.stdout);
const browserMatches = cli.stdout.includes('### Browser') ? cli.stdout.match(/Browser `(.+)` opened with pid (\d+)\./) : undefined;
- const [, , daemonPid] = browserMatches ?? [];
+ const daemonPid = browserMatches?.[2] ?? parseJsonPid(cli.stdout);
const dashboardMatches = cli.stdout.includes('### Dashboard') ? cli.stdout.match(/Dashboard opened with pid (\d+)\./) : undefined;
const dashboardPid = dashboardMatches?.[1];
@@ -176,6 +176,13 @@ async function runCli(childProcess: CommonFixtures['childProcess'], args: string
});
}
+function parseJsonPid(stdout: string) {
+ try {
+ return JSON.parse(stdout).pid;
+ } catch {
+ }
+}
+
function loadAttachments(output: string) {
// attachments look like md links - [Page as pdf](.playwright-cli/page-2026-01-22T23-13-56-347Z.pdf)
const match = output.match(/- \[(.+)\]\((.+)\)/g);