run_test
Execute browser automation tests in Selenix-MCP and receive pass/fail results for each command, with completion within 2 minutes.
Instructions
Run a test and wait for it to complete. Returns the pass/fail result for each command. This operation may take up to 2 minutes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| test_id | No | Optional test ID. If omitted, runs the active test. |
Implementation Reference
- src/bridge-client.ts:24-71 (handler)The `call` method in `BridgeClient` acts as the generic handler for all tool requests, including `run_test`. It forwards the request to the Selenix API via an HTTP POST request.
export class BridgeClient { async call(endpoint: string, body: Record<string, unknown> = {}): Promise<unknown> { // Re-read config on every call so we pick up new tokens after Selenix restarts const config = readConfig() return new Promise((resolve, reject) => { const data = JSON.stringify(body) const req = http.request( { hostname: '127.0.0.1', port: config.port, path: `/api/${endpoint}`, method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${config.token}`, 'Content-Length': Buffer.byteLength(data), }, timeout: 180000, // 3 minutes for long-running operations like run_test }, (res) => { let responseData = '' res.on('data', (chunk: string) => (responseData += chunk)) res.on('end', () => { try { resolve(JSON.parse(responseData)) } catch { resolve({ raw: responseData }) } }) } ) req.on('error', (err) => reject( new Error( `Cannot connect to Selenix bridge at 127.0.0.1:${config.port}. ` + `Is Selenix running with MCP Server enabled? (${err.message})` ) ) ) req.on('timeout', () => { req.destroy() reject(new Error('Request timed out after 180 seconds')) }) req.write(data) req.end() }) } - src/tools.ts:202-214 (schema)The tool definition for `run_test`, specifying its schema and documentation.
name: 'run_test', description: 'Run a test and wait for it to complete. Returns the pass/fail result for each command. This operation may take up to 2 minutes.', inputSchema: { type: 'object' as const, properties: { test_id: { type: 'string', description: 'Optional test ID. If omitted, runs the active test.', }, }, }, }, - src/index.ts:21-79 (registration)The request handler in `src/index.ts` routes incoming tool calls to the `bridge.call` method, effectively registering `run_test` as a callable tool.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params try { const result = (await bridge.call(name, (args as Record<string, unknown>) || {})) as Record<string, unknown> // Check for bridge-level errors if (result && typeof result === 'object' && 'error' in result) { return { content: [ { type: 'text' as const, text: `Error: ${result.error}` }, ], isError: true, } } // Special handling for screenshot — return as image content if (name === 'get_screenshot' && result.screenshot) { const screenshotStr = result.screenshot as string const base64Data = screenshotStr.replace( /^data:image\/\w+;base64,/, '' ) return { content: [ { type: 'image' as const, data: base64Data, mimeType: 'image/jpeg', }, { type: 'text' as const, text: `Screenshot of: ${result.title || 'unknown'} (${result.url || 'unknown'})`, }, ], } } // All other tools return text/JSON return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2), }, ], } } catch (error) { return { content: [ { type: 'text' as const, text: `Error: ${(error as Error).message}`, }, ], isError: true, } } })