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): unflake idle timeout and surface Firefox click hangs in CLI tests (#42872)

Yury Semikhatskye125b2ff24ad
diff --git a/tests/mcp/cli-core.spec.ts b/tests/mcp/cli-core.spec.ts
index 790ca85d6f..264458dccb 100644
--- a/tests/mcp/cli-core.spec.ts
+++ b/tests/mcp/cli-core.spec.ts
@@ -54,10 +54,10 @@ await page.getByRole('button', { name: 'Submit' }).click();
\`\`\``);
});
-test('click link', async ({ cli, server, mcpBrowser }) => {
+test('click link', async ({ cli, server }) => {
server.setContent('/', `<a href="/hello-world">Hello, world!</a>`, 'text/html');
- const { snapshot } = await cli('open', server.PREFIX, { env: { PLAYWRIGHT_MCP_TIMEOUT_ACTION: mcpBrowser === 'firefox' ? '30000' : '' } });
+ const { snapshot } = await cli('open', server.PREFIX);
expect(snapshot).toContain(`- link \"Hello, world!\" [ref=e2]`);
const { output: clickOutput, snapshot: clickSnapshot } = await cli('click', 'e2');
diff --git a/tests/mcp/cli-keyboard.spec.ts b/tests/mcp/cli-keyboard.spec.ts
index 61be3bdf60..f9ed831e7b 100644
--- a/tests/mcp/cli-keyboard.spec.ts
+++ b/tests/mcp/cli-keyboard.spec.ts
@@ -19,7 +19,8 @@ import { test, expect } from './cli-fixtures';
test('press', async ({ cli, server }) => {
server.setContent('/', `<input type=text>`, 'text/html');
await cli('open', server.PREFIX);
- await cli('click', 'e2');
+ const { output: clickOutput } = await cli('click', 'e2');
+ expect(clickOutput).not.toContain('### Error');
await cli('press', 'h');
const { inlineSnapshot } = await cli('snapshot');
expect(inlineSnapshot).toBe(`- textbox [active] [ref=e2]: h`);
@@ -28,7 +29,8 @@ test('press', async ({ cli, server }) => {
test('keydown keyup', async ({ cli, server }) => {
server.setContent('/', `<input type=text>`, 'text/html');
await cli('open', server.PREFIX);
- await cli('click', 'e2');
+ const { output: clickOutput } = await cli('click', 'e2');
+ expect(clickOutput).not.toContain('### Error');
await cli('keydown', 'h');
await cli('keyup', 'h');
const { inlineSnapshot } = await cli('snapshot');
diff --git a/tests/mcp/cli-session.spec.ts b/tests/mcp/cli-session.spec.ts
index 58ce16b499..bbbc039b19 100644
--- a/tests/mcp/cli-session.spec.ts
+++ b/tests/mcp/cli-session.spec.ts
@@ -56,7 +56,8 @@ test('idle timeout shuts the session down', async ({ cli, server }) => {
const { output } = await cli('list');
expect(output).toContain('- default:');
- await expect.poll(async () => (await cli('list')).output).toContain('(no browsers)');
+ // Firefox on Windows takes several seconds to shut down after the idle timer fires.
+ await expect.poll(async () => (await cli('list')).output, { timeout: 20_000 }).toContain('(no browsers)');
const { output: afterOutput } = await cli('snapshot');
expect(afterOutput).toContain(`The browser 'default' is not open, please run open first`);
});