Cypress uses the Mocha framework for test automation. In Cypress, we can use JSON and Excel files as test data. The Cypress automation framework uses fixtures to store test data files in JSON format.
You can read a JSON file from the fixtures folder using the cy.fixture() command. The following script can be used to read data from the fixtures folder:
Here’s a simple example of a JSON file containing a username and password.
You can save this in your fixtures folder as testData.json:
{
“username”: “testUser123”,
“password”: “SecurePass@2025”
}
Cypress Script to read testData.json:
cy.fixture(‘testData.json’).then((data) => {
// Use the data object here
cy.log(data.username);
cy.log(data.password);
});