← Back to library
Playwrightfixturesintermediatev1.20+
Load a JSON fixture from disk
Read a JSON file using Node's fs and use the data to drive test inputs.
1import { test, expect } from '@playwright/test';
2import fs from 'fs';
3import path from 'path';
4
5// tests/fixtures/user.json → { "name": "Alice", "email": "alice@test.com" }
6const user = JSON.parse(
7 fs.readFileSync(path.join(__dirname, 'fixtures/user.json'), 'utf-8')
8);
9
10test('fills form from fixture data', async ({ page }) => {
11 await page.goto('/create-user');
12
13 await page.getByLabel('Name').fill(user.name);
14 await page.getByLabel('Email').fill(user.email);
15 await page.getByRole('button', { name: 'Submit' }).click();
16
17 await expect(page.getByText(`Welcome, ${user.name}`)).toBeVisible();
18});#fixture#json#readFileSync#data-driven