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
fix(test): provisional mcp video test fix (#38594)
Pavel Feldman177494dd4a38
diff --git a/tests/mcp/fixtures.ts b/tests/mcp/fixtures.tsindex 6a3e609f09..352e7f9ab4 100644--- a/tests/mcp/fixtures.ts+++ b/tests/mcp/fixtures.ts@@ -124,7 +124,11 @@ export const test = serverTest.extend<TestFixtures & TestOptions, WorkerFixtures};});}- const env = { ...process.env, ...options?.env };+ const env = {+ ...process.env,+ PW_TMPDIR_FOR_TEST: testInfo.outputPath('tmp'),+ ...options?.env+ };const { transport, stderr } = await createTransport(mcpServerType, { args, env, cwd: options?.cwd || test.info().outputPath() });let stderrBuffer = '';stderr?.on('data', data => {diff --git a/tests/mcp/tracing.spec.ts b/tests/mcp/tracing.spec.tsindex 420534c92f..5d8ae0c347 100644--- a/tests/mcp/tracing.spec.ts+++ b/tests/mcp/tracing.spec.ts@@ -70,17 +70,15 @@ test('check that trace is saved with browser_start_tracing', async ({ startClien});test('check that trace is saved with browser_start_tracing (no output dir)', async ({ startClient, server }, testInfo) => {- const outputDir = testInfo.outputPath();-const { client } = await startClient({args: ['--caps=tracing'],- env: { ...process.env, PW_TMPDIR_FOR_TEST: outputDir },});+ const tmpDir = testInfo.outputPath('tmp');expect(await client.callTool({name: 'browser_start_tracing',})).toHaveResponse({- result: expect.stringContaining(`Tracing started, saving to ${outputDir}`),+ result: expect.stringContaining(`Tracing started, saving to ${tmpDir}`),});expect(await client.callTool({@@ -96,10 +94,10 @@ test('check that trace is saved with browser_start_tracing (no output dir)', asyresult: expect.stringMatching(/trace-\d+.trace/)});- const folders = await fs.promises.readdir(path.join(outputDir, 'playwright-mcp-output'));+ const folders = await fs.promises.readdir(path.join(tmpDir, 'playwright-mcp-output'));expect(folders.length).toBe(1);expect(folders[0]).toMatch(/\d+/);- const files = await fs.promises.readdir(path.join(outputDir, 'playwright-mcp-output', folders[0], 'traces'));+ const files = await fs.promises.readdir(path.join(tmpDir, 'playwright-mcp-output', folders[0], 'traces'));expect(files).toEqual(['resources',expect.stringMatching(/trace-\d+\.network/),diff --git a/tests/mcp/video.spec.ts b/tests/mcp/video.spec.tsindex 0da9d2653e..b0f6807956 100644--- a/tests/mcp/video.spec.ts+++ b/tests/mcp/video.spec.ts@@ -16,6 +16,7 @@import fs from 'fs';import { test, expect } from './fixtures';+import type { Client } from '@modelcontextprotocol/sdk/client/index.js';for (const mode of ['isolated', 'persistent']) {test(`should work with --save-video (${mode})`, async ({ startClient, server }, testInfo) => {@@ -29,32 +30,12 @@ for (const mode of ['isolated', 'persistent']) {],});- expect(await client.callTool({- name: 'browser_navigate',- arguments: { url: server.HELLO_WORLD },- })).toHaveResponse({- code: expect.stringContaining(`page.goto('http://localhost`),- });-- await client.callTool({- name: 'browser_evaluate',- arguments: {- function: `async () => {- document.body.style.backgroundColor = "red";- await new Promise(resolve => setTimeout(resolve, 100));- document.body.style.backgroundColor = "green";- await new Promise(resolve => setTimeout(resolve, 100));- document.body.style.backgroundColor = "blue";- await new Promise(resolve => setTimeout(resolve, 100));- }`,- },- });-- expect(await client.callTool({- name: 'browser_close',- })).toHaveResponse({- code: expect.stringContaining(`page.close()`),- });+ await navigateToTestPage(client, server);+ await expect(async () => {+ await produceFrames(client);+ await checkIntermediateVideoFileExists();+ }).toPass();+ await closeBrowser(client);const [file] = await fs.promises.readdir(outputDir);expect(file).toMatch(/page-.*\.webm/);@@ -79,34 +60,52 @@ for (const mode of ['isolated', 'persistent']) {],});- expect(await client.callTool({- name: 'browser_navigate',- arguments: { url: server.HELLO_WORLD },- })).toHaveResponse({- code: expect.stringContaining(`page.goto('http://localhost`),- });+ await navigateToTestPage(client, server);+ await expect(async () => {+ await produceFrames(client);+ await checkIntermediateVideoFileExists(videosDir);+ }).toPass();+ await closeBrowser(client);+ });+}- await client.callTool({- name: 'browser_evaluate',- arguments: {- function: `async () => {- document.body.style.backgroundColor = "red";- await new Promise(resolve => setTimeout(resolve, 100));- document.body.style.backgroundColor = "green";- await new Promise(resolve => setTimeout(resolve, 100));- document.body.style.backgroundColor = "blue";- await new Promise(resolve => setTimeout(resolve, 100));- }`,- },- });+async function navigateToTestPage(client: Client, server: any) {+ expect(await client.callTool({+ name: 'browser_navigate',+ arguments: { url: server.HELLO_WORLD },+ })).toHaveResponse({+ code: expect.stringContaining(`page.goto('http://localhost`),+ });+}- expect(await client.callTool({- name: 'browser_close',- })).toHaveResponse({- code: expect.stringContaining(`page.close()`),- });+async function closeBrowser(client: Client) {+ expect(await client.callTool({+ name: 'browser_close',+ })).toHaveResponse({+ code: expect.stringContaining(`page.close()`),+ });+}- const [file] = await fs.promises.readdir(videosDir);- expect(file).toMatch(/.*.\webm/);+async function produceFrames(client: Client) {+ expect(await client.callTool({+ name: 'browser_evaluate',+ arguments: {+ function: `async () => {+ document.body.style.backgroundColor = "red";+ await new Promise(resolve => setTimeout(resolve, 100));+ document.body.style.backgroundColor = "green";+ await new Promise(resolve => setTimeout(resolve, 100));+ document.body.style.backgroundColor = "blue";+ await new Promise(resolve => setTimeout(resolve, 100));+ return 'ok';+ }`,+ },+ })).toHaveResponse({+ result: '"ok"',});}++async function checkIntermediateVideoFileExists(videosDir?: string) {+ const files = await fs.promises.readdir(videosDir ?? test.info().outputPath('tmp', 'playwright-mcp-output'));+ expect(files[0]).toMatch(/\.webm/);+}