How to read test data from cypress

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);
});

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , Smart Fitness Guide , CodesToolbox , Testing Forum
Scroll to Top
0
Would love your thoughts, please comment.x
()
x