← Back to library
Cypressfixturesintermediatev10+

Load and use a JSON fixture

Read test data from a fixture file and use it to fill form fields.

1// cypress/fixtures/user.json → { "name": "Alice", "email": "alice@test.com", "role": "admin" }
2
3it('fills form from fixture data', () => {
4  cy.fixture('user').then((user) => {
5    cy.visit('/create-user');
6
7    cy.get('[name="name"]').type(user.name);
8    cy.get('[name="email"]').type(user.email);
9    cy.get('select[name="role"]').select(user.role);
10
11    cy.get('[type="submit"]').click();
12    cy.contains(`Welcome, ${user.name}`).should('be.visible');
13  });
14});
#fixture#json#cy.fixture#data-driven