Screenshots as Evidence
Why This Matters
UI tests fail with a screenshot attached, and the screenshot often says more than the stack trace: a cookie banner over the button, an error toast, a half-loaded page, a label that changed. Claude can read images, so TestPilot should be able to look.
The failure
t-003 in the fixture fails with:
locator.click: Timeout 30000ms exceeded.
waiting for getByRole('button', { name: 'Log in' })
From the error alone this could be a slow page (flaky), a broken environment, or a changed button. The screenshot taken at the moment of failure shows a button labelled Sign in. That one image turns a guess into a test bug with evidence.
Sending an image
A message’s content can be a list of blocks: text and images together.
import { readFile } from "node:fs/promises";
const png = await readFile(result.screenshot!);
const content = [
{ type: "text", text: buildTriageMessage(run, result) },
{
type: "image",
source: { type: "base64", media_type: "image/png", data: png.toString("base64") },
},
{ type: "text", text: "The image above is the screenshot taken when the test failed." },
];
Add an optional screenshot path to TestResult in src/types.ts and send the image only when one exists.
Ask for what it sees, not just what it concludes
An image is evidence like any log line, so treat it the same way. Extend the evidence rule in the system prompt:
When a screenshot is provided, describe in the evidence what is visible that supports your verdict (for example: “button text is ‘Sign in’”).
A verdict that says “test_bug: the button is labelled Sign in, the test looks for Log in” can be checked in seconds by a human looking at the same image.
Limits and costs
- Images cost tokens by area: about one token per 28 × 28 pixel tile, and large images are scaled down to a maximum. Crop to the part that matters rather than sending a full-page screenshot.
- Put images before the text that asks about them; Claude works best with that order.
- Send only what helps. The log is often enough; an image for every failure in a 40-failure run adds up.
- Check the current limits for image size and number of images per request in Anthropic’s documentation.
Privacy
Screenshots from test environments can contain things that must never leave your company: real customer data copied into staging, email addresses, tokens in a URL bar, internal dashboards. Before you send screenshots to any external service:
- use synthetic test data in the environments you screenshot
- crop to the area under test where you can
- agree with your team (and your security officer) what may be sent
Exercise
Add fixtures/screenshots/t-003.png (a screenshot of a login form with a Sign in button), wire it into the fixture and the triage, and compare the verdict for t-003 with and without the image.