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(cli): fix tracing cli (#39182)
Pavel Feldman014f80ef8aca
diff --git a/packages/playwright-core/src/server/browserType.ts b/packages/playwright-core/src/server/browserType.tsindex ec377c1498..a90f4be5f8 100644--- a/packages/playwright-core/src/server/browserType.ts+++ b/packages/playwright-core/src/server/browserType.ts@@ -152,8 +152,6 @@ export abstract class BrowserType extends SdkObject {args = [],executablePath = null,} = options;- await this._createArtifactDirs(options);-const tempDirectories: string[] = [];const artifactsDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-artifacts-'));tempDirectories.push(artifactsDir);@@ -281,13 +279,6 @@ export abstract class BrowserType extends SdkObject {}}- async _createArtifactDirs(options: types.LaunchOptions): Promise<void> {- if (options.downloadsPath)- await fs.promises.mkdir(options.downloadsPath, { recursive: true });- if (options.tracesDir)- await fs.promises.mkdir(options.tracesDir, { recursive: true });- }-async connectOverCDP(progress: Progress, endpointURL: string, options: { slowMo?: number, timeout?: number, headers?: types.HeadersArray, isLocal?: boolean }): Promise<Browser> {throw new Error('CDP connections are only supported by Chromium');}diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.tsindex bcc69d40f1..39bd23fbf5 100644--- a/packages/playwright-core/src/server/chromium/chromium.ts+++ b/packages/playwright-core/src/server/chromium/chromium.ts@@ -183,8 +183,6 @@ export class Chromium extends BrowserType {}override async _launchWithSeleniumHub(progress: Progress, hubUrl: string, options: types.LaunchOptions): Promise<CRBrowser> {- await progress.race(this._createArtifactDirs(options));-if (!hubUrl.endsWith('/'))hubUrl = hubUrl + '/';diff --git a/packages/playwright/src/mcp/browser/browserContextFactory.ts b/packages/playwright/src/mcp/browser/browserContextFactory.tsindex 4feb0835f2..a5e1cffd65 100644--- a/packages/playwright/src/mcp/browser/browserContextFactory.ts+++ b/packages/playwright/src/mcp/browser/browserContextFactory.ts@@ -23,7 +23,7 @@ import * as playwright from 'playwright-core';import { registryDirectory } from 'playwright-core/lib/server/registry/index';import { startTraceViewerServer } from 'playwright-core/lib/server';import { logUnhandledError, testDebug } from '../log';-import { outputFile } from './config';+import { outputDir, outputFile } from './config';import { firstRootPath } from '../sdk/server';import type { FullConfig } from './config';@@ -352,9 +352,7 @@ export class SharedContextFactory implements BrowserContextFactory {}async function computeTracesDir(config: FullConfig, clientInfo: ClientInfo): Promise<string | undefined> {- if (!config.saveTrace && !config.capabilities?.includes('devtools'))- return;- return await outputFile(config, clientInfo, `traces`, { origin: 'code' });+ return path.resolve(outputDir(config, clientInfo), 'traces');}async function browserContextOptionsFromConfig(config: FullConfig, clientInfo: ClientInfo): Promise<playwright.BrowserContextOptions> {diff --git a/packages/playwright/src/mcp/program.ts b/packages/playwright/src/mcp/program.tsindex 85b926ea1d..afaabf409f 100644--- a/packages/playwright/src/mcp/program.ts+++ b/packages/playwright/src/mcp/program.ts@@ -121,7 +121,8 @@ export function decorateCommand(command: Command, version: string) {console.log(`### Success\nDaemon listening on ${socketPath}`);console.log('<EOF>');} catch (error) {- console.log(`### Error\n${error.message}`);+ const message = process.env.PWDEBUGIMPL ? (error as Error).stack || (error as Error).message : (error as Error).message;+ console.log(`### Error\n${message}`);console.log('<EOF>');}return;diff --git a/packages/playwright/src/mcp/terminal/command.ts b/packages/playwright/src/mcp/terminal/command.tsindex 09ae67611a..8d3add262a 100644--- a/packages/playwright/src/mcp/terminal/command.ts+++ b/packages/playwright/src/mcp/terminal/command.ts@@ -71,11 +71,11 @@ function zodParse(schema: zodType.ZodAny, data: unknown, type: 'option' | 'argumconst label = type === 'option' ? `'--${prop}' option` : `'${prop}' argument`;switch (issue.code) {case 'invalid_type':- return 'error: ' + label + ': ' + issue.message.toLowerCase().replace(/invalid input:/, '').trim();+ return 'error: ' + label + ': ' + issue.message.replace(/Invalid input:/, '').trim();case 'unrecognized_keys':return 'error: unknown ' + label;default:- return 'error: ' + label + ': ' + issue.message.toLowerCase();+ return 'error: ' + label + ': ' + issue.message;}});}).flat().join('\n'));diff --git a/packages/playwright/src/mcp/terminal/daemon.ts b/packages/playwright/src/mcp/terminal/daemon.tsindex 4a1cf9abd5..321e9f790b 100644--- a/packages/playwright/src/mcp/terminal/daemon.ts+++ b/packages/playwright/src/mcp/terminal/daemon.ts@@ -119,7 +119,8 @@ export async function startMcpDaemonServer(}} catch (e) {daemonDebug('command failed', e);- await connection.send({ id, error: (e as Error).message });+ const error = process.env.PWDEBUGIMPL ? (e as Error).stack || (e as Error).message : (e as Error).message;+ await connection.send({ id, error });}};});diff --git a/tests/mcp/cli-devtools.spec.ts b/tests/mcp/cli-devtools.spec.tsindex c49d2c5905..8bdd8e3397 100644--- a/tests/mcp/cli-devtools.spec.ts+++ b/tests/mcp/cli-devtools.spec.ts@@ -14,6 +14,8 @@* limitations under the License.*/+import fs from 'fs';+import path from 'path';import { test, expect } from './cli-fixtures';test('console', async ({ cli, server }) => {@@ -71,13 +73,22 @@ test('network --clear', async ({ cli, server }) => {expect(attachments[0].data.toString()).not.toContain(`[GET] ${`${server.PREFIX}/hello-world`} => [200] OK`);});-test('tracing-start-stop', async ({ cli, server }) => {+test('tracing-start-stop', async ({ cli, server }, testInfo) => {await cli('open', server.HELLO_WORLD);const { output } = await cli('tracing-start');expect(output).toContain('Trace recording started');await cli('eval', '() => fetch("/hello-world")');+const { output: tracingStopOutput } = await cli('tracing-stop');expect(tracingStopOutput).toContain('Trace recording stopped');+ const [, timestamp] = tracingStopOutput.match(/trace-(\d+)\.trace/);+ expect(tracingStopOutput).toContain(`- [Trace](.playwright-cli${path.sep}traces${path.sep}trace-${timestamp}.trace)`);+ expect(tracingStopOutput).toContain(`- [Network log](.playwright-cli${path.sep}traces${path.sep}trace-${timestamp}.network)`);+ expect(tracingStopOutput).toContain(`- [Resources](.playwright-cli${path.sep}traces${path.sep}resources)`);++ expect(fs.existsSync(testInfo.outputPath('.playwright-cli', 'traces', 'resources'))).toBeTruthy();+ expect(fs.existsSync(testInfo.outputPath('.playwright-cli', 'traces', `trace-${timestamp}.trace`))).toBeTruthy();+ expect(fs.existsSync(testInfo.outputPath('.playwright-cli', 'traces', `trace-${timestamp}.network`))).toBeTruthy();});test('video-start-stop', async ({ cli, server }) => {diff --git a/tests/mcp/cli-parsing.spec.ts b/tests/mcp/cli-parsing.spec.tsindex 3998b464a6..f8d1c448ac 100644--- a/tests/mcp/cli-parsing.spec.ts+++ b/tests/mcp/cli-parsing.spec.ts@@ -35,7 +35,7 @@ test('wrong option type', async ({ cli, server }) => {expect(boolean.error).toContain(`boolean option '--submit' should not be passed with '=value', use '--submit' or '--no-submit' instead`);const status = await cli('route', '.', '--status=OK');expect(status.exitCode).toBe(1);- expect(status.error).toContain(`error: '--status' option: expected number, received string`);+ expect(status.error).toContain(`error: '--status' option: expected number, received 'OK'`);});test('arg after boolean option', async ({ cli, server }) => {