Skip to content

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

fix(mcp): proper error message for test_debug without context (#39404)

Simon Knott3f3c0f349b4e
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index f430dafdc5..b615f95345 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -231,10 +231,12 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
});
}, { box: true }],
- _setupContextOptions: [async ({ playwright, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
+ _setupContextOptions: [async ({ playwright, actionTimeout, navigationTimeout, testIdAttribute }, use, _testInfo) => {
+ const testInfo = _testInfo as TestInfoImpl;
if (testIdAttribute)
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
testInfo.snapshotSuffix = process.platform;
+ testInfo._onCustomMessageCallback = () => Promise.reject(new Error('Only tests that use default Playwright context or page fixture support test_debug'));
if (debugMode() === 'inspector')
(testInfo as TestInfoImpl)._setDebugMode();
diff --git a/tests/mcp/test-debug.spec.ts b/tests/mcp/test-debug.spec.ts
index fbda63b595..9e25bb53ed 100644
--- a/tests/mcp/test-debug.spec.ts
+++ b/tests/mcp/test-debug.spec.ts
@@ -438,3 +438,18 @@ Error: expect(locator).toBeVisible() failed`));
page: expect.stringContaining(`- Page URL: ${server.HELLO_WORLD}\n- Page Title: Title2`),
});
});
+
+test('test_debug (no default page fixture)', async ({ startClient }) => {
+ const { client, id } = await prepareDebugTest(startClient, `
+ import { test, expect } from '@playwright/test';
+ test('fail', async ({}) => {
+ throw new Error('failure');
+ });
+ `);
+ expect(await client.callTool({
+ name: 'test_debug',
+ arguments: {
+ test: { id, title: 'fail' },
+ },
+ })).toHaveTextResponse(expect.stringContaining(`Only tests that use default Playwright context or page fixture support test_debug`));
+});