Registry /
testing / playwright-ajv-schema-validator
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
validateSchema
✓ import { validateSchema } from 'playwright-ajv-schema-validator';
✗ const validateSchema = require('playwright-ajv-schema-validator');
Named export; use ESM only as package is ESM-first. CommonJS require may fail.
default
✓ import playwrightAjvSchemaValidator from 'playwright-ajv-schema-validator';
✗ const playwrightAjvSchemaValidator = require('playwright-ajv-schema-validator').default;
Default export only available as ESM; not recommended as the primary export is validateSchema.
validateSchema type
✓ import type { ValidateSchemaFn } from 'playwright-ajv-schema-validator';
TypeScript types are included; import type for type-checking.
Shows how to validate a Playwright API response against a JSON schema using validateSchema function.
import { test, expect } from '@playwright/test';
import { validateSchema } from 'playwright-ajv-schema-validator';
import path from 'path';
import fs from 'fs';
const schemaPath = path.resolve(__dirname, 'schemas', 'user.json');
const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
test('POST /users response schema validation', async ({ request, fixtures }) => {
const response = await request.post('https://api.example.com/users', {
data: { name: 'John' }
});
const data = await response.json();
const validationResult = validateSchema(fixtures, data, schema);
expect(validationResult.passed).toBeTruthy();
if (!validationResult.passed) {
console.error('Schema errors:', validationResult.errors);
}
});
Errors
Common errors & fixes
TypeError: fixtures.testInfo is not a function
The 'fixtures' object passed to validateSchema is not the Playwright test fixtures but an incorrect object
fixPass the first argument of your test callback, which is the 'fixtures' object provided by Playwright.
Cannot find module 'playwright-ajv-schema-validator'
Package not installed or not resolvable due to ESM/CJS mismatch
fixEnsure package is installed: npm install playwright-ajv-schema-validator. If using CJS, switch to ESM or use dynamic import.
Error: schema must be an object or array
The 'schema' argument passed to validateSchema is not a valid JSON schema object
fixEnsure schema is a parsed JSON object, not a string or undefined.
Audit
Dependencies
playwrightrequiredPeer dependency: requires Playwright for API request handling and test runner
ajvrequiredUsed for JSON schema validation engine
core-ajv-schema-validatorrequiredCore validation logic wrapper