Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_internal/browser-eval-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function startBrowserEvalMCP(options?: {
console.error("[Browser Eval Manager] Starting playwright-mcp server with verbose logging...")

// Build args for playwright-mcp
const args: string[] = ["@playwright/mcp@latest"]
const args: string[] = ["@playwright/mcp@latest", "--image-responses", "omit"]

if (options?.browser) {
args.push("--browser", options.browser)
Expand Down
73 changes: 73 additions & 0 deletions test/unit/browser-eval-screenshot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"

// Mock the mcp-client module before importing browser-eval-manager
vi.mock("../../src/_internal/mcp-client.js", () => ({
connectToMCPServer: vi.fn(),
callServerTool: vi.fn(),
listServerTools: vi.fn(),
}))

// Mock the exec function to skip installation check
vi.mock("child_process", () => ({
exec: vi.fn((cmd, callback) => {
callback(null, { stdout: "@playwright/mcp@1.0.0" })
}),
}))

import { connectToMCPServer, callServerTool } from "../../src/_internal/mcp-client.js"
import {
startBrowserEvalMCP,
stopBrowserEvalMCP,
} from "../../src/_internal/browser-eval-manager.js"
import { handler } from "../../src/tools/browser-eval.js"

describe("browser-eval playwright-mcp screenshot tool", () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(connectToMCPServer).mockResolvedValue({
client: { close: vi.fn() },
transport: { close: vi.fn() },
} as never)
})

afterEach(async () => {
await stopBrowserEvalMCP()
})

it("should pass --image-responses omit flag to playwright-mcp", async () => {
await startBrowserEvalMCP()

expect(connectToMCPServer).toHaveBeenCalledWith(
"npx",
expect.arrayContaining(["--image-responses", "omit"]),
expect.any(Object)
)
})

it("should return screenshot file path without base64 image data", async () => {
await startBrowserEvalMCP()

const screenshotPath = "/var/folders/tmp/screenshot-1234.png"
vi.mocked(callServerTool).mockResolvedValue({
content: [{ type: "text", text: `Screenshot saved to ${screenshotPath}` }],
})

const result = await handler({ action: "screenshot" })
const parsed = JSON.parse(result)

expect(parsed.success).toBe(true)
expect(parsed.action).toBe("screenshot")

// Verify response contains file path
const textContent = parsed.result.content.find(
(block: { type: string }) => block.type === "text"
)
expect(textContent.text).toContain(screenshotPath)

// Verify no base64 image data in response
const imageContent = parsed.result.content.find(
(block: { type: string }) => block.type === "image"
)
expect(imageContent).toBeUndefined()
})
})