How to Use Playwright to Validate an API Response Schema (PWT-Native and Zod)

Apr 8, 2025

In this video, Stefan Judis, Playwright ambassador, explores ways to apply schema validation for API responses. We dive into three detailed examples:

  • validating a simple RESTful GET request with known response values
  • using Playwright's `expect.any` to validate dynamic response values
  • tackling complex JSON schema validation using the Zod library.

By the end of this tutorial, you'll learn how to employ Playwright's native methods or a JSON validation library such as Zod to ensure your API responses meet expected schemas.

Source code: https://github.com/checkly/playwright-examples/tree/main/api-schema-validation

00:00 Intro

00:30 Validate API responses with known values

02:55 Validate API responses with dynamic values using `expect.any()`

04:45 Validate complex API responses with the Zod library

08:05 Using your Playwright tests with Checkly for synthetic monitoring

#playwright #syntheticmonitoring #checkly