Skip to content

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

chore(cli): better old version messages (#39184)

Pavel Feldman67075d7fab7b
diff --git a/packages/playwright/src/mcp/terminal/program.ts b/packages/playwright/src/mcp/terminal/program.ts
index f2a28ca711..a4c33333ff 100644
--- a/packages/playwright/src/mcp/terminal/program.ts
+++ b/packages/playwright/src/mcp/terminal/program.ts
@@ -83,9 +83,9 @@ class Session {
if (!this.isCompatible()) {
throw new Error(`Client is v${this._clientInfo.version}, session '${this.name}' is v${this._config.version}. Run
- playwright-cli session-restart${this.name !== 'default' ? ` ${this.name}` : ''}
+ playwright-cli${this.name !== 'default' ? ` -s=${this.name}` : ''} open
-to restart the session daemon.`);
+to restart the browser session.`);
}
}
@@ -818,9 +818,10 @@ async function renderSessionStatus(session: Session) {
const text: string[] = [];
const config = session.config();
const canConnect = await session.canConnect();
- const restartMarker = canConnect && !session.isCompatible() ? ` - v${config.version}, please reopen` : '';
text.push(`- ${session.name}:`);
- text.push(` - status: ${canConnect ? 'open' : 'closed'}${restartMarker}`);
+ text.push(` - status: ${canConnect ? 'open' : 'closed'}`);
+ if (canConnect && !session.isCompatible())
+ text.push(` - version: v${config.version} [incompatible please re-open]`);
if (config.resolvedConfig)
text.push(...renderResolvedConfig(config.resolvedConfig));
return text.join('\n');
diff --git a/tests/mcp/cli-session.spec.ts b/tests/mcp/cli-session.spec.ts
index e4fb496ed2..e437530225 100644
--- a/tests/mcp/cli-session.spec.ts
+++ b/tests/mcp/cli-session.spec.ts
@@ -207,3 +207,34 @@ test('list --all lists sessions from all workspaces', async ({ cli, server }, te
await cli('-s', 'session1', 'close', { cwd: workspace1 });
await cli('-s', 'session2', 'close', { cwd: workspace2 });
});
+
+test('incompatible version - command fails with version mismatch error', async ({ cli, server }) => {
+ await cli('open', server.HELLO_WORLD);
+
+ const { output, error, exitCode } = await cli('eval', '1+1', { env: { PLAYWRIGHT_CLI_VERSION_FOR_TEST: '9.9.9' } });
+ expect(exitCode).not.toBe(0);
+ const fullOutput = output + error;
+ expect(fullOutput).toContain('Client is v9.9.9');
+ expect(fullOutput).toContain('playwright-cli open');
+ expect(fullOutput).toContain('to restart the browser session');
+});
+
+test('incompatible version - named session includes session name in error', async ({ cli, server }) => {
+ await cli('-s', 'mysession', 'open', server.HELLO_WORLD);
+
+ const { output, error, exitCode } = await cli('-s', 'mysession', 'eval', '1+1', { env: { PLAYWRIGHT_CLI_VERSION_FOR_TEST: '9.9.9' } });
+ expect(exitCode).not.toBe(0);
+ const fullOutput = output + error;
+ expect(fullOutput).toContain('Client is v9.9.9');
+ expect(fullOutput).toContain(`session 'mysession'`);
+ expect(fullOutput).toContain('playwright-cli -s=mysession open');
+});
+
+test('incompatible version - list shows incompatible warning', async ({ cli, server }) => {
+ await cli('open', server.HELLO_WORLD);
+
+ const { output } = await cli('list', { env: { PLAYWRIGHT_CLI_VERSION_FOR_TEST: '9.9.9' } });
+ expect(output).toContain('### Browsers');
+ expect(output).toContain('- default:');
+ expect(output).toContain('[incompatible please re-open]');
+});