Skip to content

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

chore(mcp): do not mark test run result as error (#37506)

Yury Semikhatskycd8f3f1c1246
diff --git a/packages/playwright/src/mcp/test/testTools.ts b/packages/playwright/src/mcp/test/testTools.ts
index b5ed411b0c..ae37d68453 100644
--- a/packages/playwright/src/mcp/test/testTools.ts
+++ b/packages/playwright/src/mcp/test/testTools.ts
@@ -66,7 +66,7 @@ export const runTests = defineTestTool({
const configDir = context.configLocation.configDir;
const reporter = new ListReporter({ configDir, screen, includeTestId: true });
const testRunner = await context.createTestRunner();
- const result = await testRunner.runTests(reporter, {
+ await testRunner.runTests(reporter, {
locations: params.locations,
projects: params.projects,
disableConfigReporters: true,
@@ -76,8 +76,7 @@ export const runTests = defineTestTool({
return {
content: [
{ type: 'text', text },
- ],
- isError: result.status !== 'passed',
+ ]
};
},
});
diff --git a/tests/mcp/test-tools.spec.ts b/tests/mcp/test-tools.spec.ts
index 9c64551ae2..b13432d81f 100644
--- a/tests/mcp/test-tools.spec.ts
+++ b/tests/mcp/test-tools.spec.ts
@@ -96,6 +96,26 @@ test('test_run', async ({ startClient }) => {
expect(text).not.toContain(`../../test-results`);
});
+test('test_run for a failed tests is not an error', async ({ startClient }) => {
+ await writeFiles({
+ 'a.test.ts': `
+ import { test, expect } from '@playwright/test';
+ test('fails', () => { expect(1).toBe(2); });
+ `,
+ });
+
+ const { client } = await startClient();
+ const response = await client.callTool({
+ name: 'test_run',
+ });
+
+ const text = response.content[0].text;
+ // The tool run has succeeded, even though the test has failed.
+ expect(response.isError).toBeFalsy();
+
+ expect(text).toContain(`1 failed`);
+});
+
test('test_run filters', async ({ startClient }) => {
await writeFiles({
'playwright.config.ts': `