Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(mcp): allow passing no test to set up page (#37402)
Pavel Feldman6e843860e3bb
diff --git a/packages/playwright/src/mcp/test/testTools.ts b/packages/playwright/src/mcp/test/testTools.tsindex bab6161de8..faa0c8ac10 100644--- a/packages/playwright/src/mcp/test/testTools.ts+++ b/packages/playwright/src/mcp/test/testTools.ts@@ -14,6 +14,9 @@* limitations under the License.*/+import fs from 'fs';+import path from 'path';+import { noColors } from 'playwright-core/lib/utils';import { z } from '../sdk/bundle';@@ -119,9 +122,10 @@ export const setupPage = defineTestTool({schema: {name: 'test_setup_page',title: 'Setup page',- description: 'Runs a blank test to setup the page for interaction',+ description: 'Setup the page for test',inputSchema: z.object({- testLocation: z.string().describe('Location of the blank test to use for setup. For example: "test/e2e/file.spec.ts:20"'),+ project: z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),+ testLocation: z.string().optional().describe('Location of the test to use for setup. For example: "test/e2e/file.spec.ts:20". Sets up blank page if no location is provided.'),}),type: 'readOnly',},@@ -131,9 +135,23 @@ export const setupPage = defineTestTool({const configDir = context.configLocation.configDir;const reporter = new ListReporter({ configDir, screen });const testRunner = await context.createTestRunner();++ let testLocation = params.testLocation;+ if (!testLocation) {+ testLocation = '.template.spec.ts';+ const templateFile = path.join(configDir, testLocation);+ if (!fs.existsSync(templateFile)) {+ await fs.promises.writeFile(templateFile, `+ import { test, expect } from '@playwright/test';+ test('template', async ({ page }) => {});+ `);+ }+ }+const result = await testRunner.runTests(reporter, {headed: !context.options?.headless,- locations: [params.testLocation],+ locations: [testLocation],+ projects: params.project ? [params.project] : undefined,timeout: 0,workers: 1,pauseAtEnd: true,diff --git a/tests/mcp/test-tools.spec.ts b/tests/mcp/test-tools.spec.tsindex cccfd295e7..37de4d325a 100644--- a/tests/mcp/test-tools.spec.ts+++ b/tests/mcp/test-tools.spec.ts@@ -348,6 +348,17 @@ test('test_setup_page', async ({ startClient }) => {});});+test('test_setup_page (no test location)', async ({ startClient }) => {+ const { client } = await startClient();+ expect(await client.callTool({+ name: 'test_setup_page',+ arguments: {},+ })).toHaveTextResponse(`### Paused at end of test. ready for interaction++### Current page snapshot:+`);+});+async function prepareDebugTest(startClient: StartClient) {await writeFiles({'a.test.ts': `