playwright_assert_response
Validate HTTP responses in browser automation tests by checking response body content against expected values after initiating a wait operation.
Instructions
Wait for and validate a previously initiated HTTP response wait operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Identifier of the HTTP response initially expected using `Playwright_expect_response`. | |
| value | No | Data to expect in the body of the HTTP response. If provided, the assertion will fail if this value is not found in the response body. |
Implementation Reference
- src/tools/browser/response.ts:42-86 (handler)The AssertResponseTool class implements the core logic for the 'playwright_assert_response' tool. It retrieves a previously set response promise, awaits the response, parses the JSON body, optionally asserts if a specific value is present, and returns detailed success or error information.export class AssertResponseTool extends BrowserToolBase { /** * Execute the assert response tool */ async execute(args: AssertResponseArgs, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async () => { if (!args.id) { return createErrorResponse("Missing required parameter: id must be provided"); } const responsePromise = responsePromises.get(args.id); if (!responsePromise) { return createErrorResponse(`No response wait operation found with ID: ${args.id}`); } try { const response = await responsePromise; const body = await response.json(); if (args.value) { const bodyStr = JSON.stringify(body); if (!bodyStr.includes(args.value)) { const messages = [ `Response body does not contain expected value: ${args.value}`, `Actual body: ${bodyStr}`, ]; return createErrorResponse(messages.join("\n")); } } const messages = [ `Response assertion for ID ${args.id} successful`, `URL: ${response.url()}`, `Status: ${response.status()}`, `Body: ${JSON.stringify(body, null, 2)}`, ]; return createSuccessResponse(messages.join("\n")); } catch (error) { return createErrorResponse(`Failed to assert response: ${(error as Error).message}`); } finally { responsePromises.delete(args.id); } }); } }
- src/tools.ts:354-372 (schema)The input schema definition for the 'playwright_assert_response' tool, specifying parameters 'id' (required) and optional 'value' for response body assertion.{ name: "playwright_assert_response", description: "Wait for and validate a previously initiated HTTP response wait operation.", inputSchema: { type: "object", properties: { id: { type: "string", description: "Identifier of the HTTP response initially expected using `Playwright_expect_response`.", }, value: { type: "string", description: "Data to expect in the body of the HTTP response. If provided, the assertion will fail if this value is not found in the response body.", }, }, required: ["id"], }, },
- src/toolHandler.ts:612-613 (registration)Registration of the 'playwright_assert_response' tool in the main tool dispatch switch statement, delegating execution to the AssertResponseTool instance.case "playwright_assert_response": return await assertResponseTool.execute(args, context);
- src/tools.ts:506-506 (registration)The tool name is listed in the BROWSER_TOOLS array, used for conditional browser launching."playwright_assert_response",