From 5df011ad4b0130960b3eb9856b2e7d3b0e1e73ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8A=E3=81=8C=E3=81=A9=E3=82=89?= <61941819+ogadra@users.noreply.github.com> Date: Sun, 4 May 2025 12:11:17 +0900 Subject: [PATCH] feat(cli): set `outputDir` via cli options (#338) --- README.md | 1 + src/config.ts | 2 ++ src/program.ts | 1 + tests/screenshot.spec.ts | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/README.md b/README.md index d69ab09..9b84272 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ The Playwright MCP server supports the following command-line options: - `--port `: Port to listen on for SSE transport - `--host `: Host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces. - `--vision`: Run server that uses screenshots (Aria snapshots are used by default) +- `--output-dir`: Directory for output files - `--config `: Path to the configuration file ### User profile diff --git a/src/config.ts b/src/config.ts index 501c434..ee9e149 100644 --- a/src/config.ts +++ b/src/config.ts @@ -36,6 +36,7 @@ export type CLIOptions = { host?: string; vision?: boolean; config?: string; + outputDir?: string; }; const defaultConfig: Config = { @@ -110,6 +111,7 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise c.trim() as ToolCapability), vision: !!cliOptions.vision, + outputDir: cliOptions.outputDir, }; } diff --git a/src/program.ts b/src/program.ts index 58fc1a1..660749e 100644 --- a/src/program.ts +++ b/src/program.ts @@ -38,6 +38,7 @@ program .option('--port ', 'Port to listen on for SSE transport.') .option('--host ', 'Host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.') .option('--vision', 'Run server that uses screenshots (Aria snapshots are used by default)') + .option('--output-dir ', 'Path to the directory for output files.') .option('--config ', 'Path to the configuration file.') .action(async options => { const config = await resolveConfig(options); diff --git a/tests/screenshot.spec.ts b/tests/screenshot.spec.ts index a6af1c3..b769a02 100644 --- a/tests/screenshot.spec.ts +++ b/tests/screenshot.spec.ts @@ -73,6 +73,28 @@ test('browser_take_screenshot (element)', async ({ client }) => { }); }); +test('--output-dir should work', async ({ startClient }, testInfo) => { + const outputDir = testInfo.outputPath('output'); + const client = await startClient({ + args: ['--output-dir', outputDir], + }); + expect(await client.callTool({ + name: 'browser_navigate', + arguments: { + url: 'data:text/html,TitleHello, world!', + }, + })).toContainTextContent(`Navigate to data:text/html`); + + await client.callTool({ + name: 'browser_take_screenshot', + arguments: {}, + }); + + expect(fs.existsSync(outputDir)).toBeTruthy(); + expect([...fs.readdirSync(outputDir)]).toHaveLength(1); +}); + + test('browser_take_screenshot (outputDir)', async ({ startClient }, testInfo) => { const outputDir = testInfo.outputPath('output'); const client = await startClient({