Test Overview
This test uses a JSON fixture file to load user data and verifies that the user name is displayed correctly on the page.
This test uses a JSON fixture file to load user data and verifies that the user name is displayed correctly on the page.
describe('User Profile Test with JSON Fixture', () => { beforeEach(() => { cy.visit('/user-profile') }) it('displays user name from fixture', () => { cy.fixture('user').then((user) => { cy.get('#user-name').should('contain.text', user.name) }) }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to '/user-profile' | User profile page is loaded in the browser | — | PASS |
| 3 | Loads JSON fixture file 'user.json' | Fixture data with user details is available | — | PASS |
| 4 | Finds element with id 'user-name' | User name element is present on the page | — | PASS |
| 5 | Checks that element '#user-name' contains text from fixture user.name | User name text is visible on the page | Assert element text equals fixture user.name | PASS |
JSON fixture files in Cypress tests?user.json in a Cypress test?cy.fixture() to load fixture files from the fixtures folder.cy.fixture() is the correct Cypress command; others do not exist or are incorrect.user.json with content:{"name": "Alice", "age": 30}cy.fixture('user.json').then((user) => {
console.log(user.name);
console.log(user.age + 5);
})cy.fixture('config.json').then((config) => {
expect(config.timeout).to.equal(5000)
})TypeError: Cannot read property 'timeout' of undefined. What is the most likely cause?config is undefined, so config.timeout fails.cy.fixture() returns undefined, causing this error.config.json does not exist or is misnamed -> Option Dusers.json containing an array of user objects:[{"id":1,"name":"Bob"},{"id":2,"name":"Carol"},{"id":3,"name":"Dave"}]id 2 has the name "Carol"?id and name.find() to get the user object where id === 2, then check its name.Pass the test and this pattern moves unknown