mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
feat(cli): set outputDir
via cli options (#338)
This commit is contained in:
parent
200cf737bb
commit
5df011ad4b
@ -77,6 +77,7 @@ The Playwright MCP server supports the following command-line options:
|
|||||||
- `--port <port>`: Port to listen on for SSE transport
|
- `--port <port>`: Port to listen on for SSE transport
|
||||||
- `--host <host>`: Host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.
|
- `--host <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)
|
- `--vision`: Run server that uses screenshots (Aria snapshots are used by default)
|
||||||
|
- `--output-dir`: Directory for output files
|
||||||
- `--config <path>`: Path to the configuration file
|
- `--config <path>`: Path to the configuration file
|
||||||
|
|
||||||
### User profile
|
### User profile
|
||||||
|
@ -36,6 +36,7 @@ export type CLIOptions = {
|
|||||||
host?: string;
|
host?: string;
|
||||||
vision?: boolean;
|
vision?: boolean;
|
||||||
config?: string;
|
config?: string;
|
||||||
|
outputDir?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultConfig: Config = {
|
const defaultConfig: Config = {
|
||||||
@ -110,6 +111,7 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise<Conf
|
|||||||
},
|
},
|
||||||
capabilities: cliOptions.caps?.split(',').map((c: string) => c.trim() as ToolCapability),
|
capabilities: cliOptions.caps?.split(',').map((c: string) => c.trim() as ToolCapability),
|
||||||
vision: !!cliOptions.vision,
|
vision: !!cliOptions.vision,
|
||||||
|
outputDir: cliOptions.outputDir,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ program
|
|||||||
.option('--port <port>', 'Port to listen on for SSE transport.')
|
.option('--port <port>', 'Port to listen on for SSE transport.')
|
||||||
.option('--host <host>', 'Host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.')
|
.option('--host <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('--vision', 'Run server that uses screenshots (Aria snapshots are used by default)')
|
||||||
|
.option('--output-dir <path>', 'Path to the directory for output files.')
|
||||||
.option('--config <path>', 'Path to the configuration file.')
|
.option('--config <path>', 'Path to the configuration file.')
|
||||||
.action(async options => {
|
.action(async options => {
|
||||||
const config = await resolveConfig(options);
|
const config = await resolveConfig(options);
|
||||||
|
@ -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,<html><title>Title</title><body>Hello, world!</body></html>',
|
||||||
|
},
|
||||||
|
})).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) => {
|
test('browser_take_screenshot (outputDir)', async ({ startClient }, testInfo) => {
|
||||||
const outputDir = testInfo.outputPath('output');
|
const outputDir = testInfo.outputPath('output');
|
||||||
const client = await startClient({
|
const client = await startClient({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user