How to write data-driven framework using Cypress?

Reading Time: 3 minutes

In this blog, we will see how to write data-driven framework using Cypress.

Cypress is an end-to-end testing framework for web test automation. Therefore, it enables the writing of automated web tests in JavaScript. Here, we will see a data-driven framework using Cypress. The use of JavaScript makes Cypress automation more intuitive. Cypress has been used as a data-driven framework with the help of fixtures. Certainly, the use of fixtures is to extract input from external files. Let’s see how to write data-driven framework using Cypress.

What is data-driven?

Data-driven testing is a test design and execution strategy. Therefore, where test scripts read data from test input data. Hence, the test data is stored in data sources like JSON, CSV, Xls, XML, and databases. Hence, the testing enables building tests with a different set of input data into single tests.

What is a cypress fixture?

As we have already discussed above, that cypress fixture helps to extract input data from external files.

Meanwhile, these fixtures come along with cypress in the fixture folder (example.json). The folder can have files in the Javascript Object Notation (JSON) or other formats.

The syntax for cypress data-driven testing is:

cy.fixture(path of test data)
cy.fixture(path of test data, encoding type)
cy.fixture(path of test data, opts)
cy.fixture(path of test data, encoding type, options)

Steps for data-driven framework

Step 1 – Initialize npm in a folder

Above all, we have to initialize npm. This will create a package.json file in the folder.

Write the following command on the VS terminal.

npm init

Step 2 – Install Cypress with npm

npm install cypress –save-dev

Firstly, a folder structure has been created automatically.

Meanwhile, a file package.json has been auto-created.

Step 3: Create a cypress structure

In conclusion, we have to create a cypress folder structure.

./node_modules/.bin/cypress open
Firstly, a folder structure has been created automatically..

Step 4: Open Cypress to create a Cypress folder structure

./node_modules/.bin/cypress open

Finally, the above command will open Cypress.

Above all, it creates a folder structure.

Step 5: Write the following code in example.json

“email”: “”,
“password”: “sample@123”

Step 6: Write the following code in one

Step 7: In conclusion, run open.js

Hence, the final output after running open.js

I hope you have enjoyed reading it. Stay tuned for more blogs.


knoldus footer

Written by 

I work with Knoldus and have experience of 8+ years in quality assurance I have good experience on SeleniumWebdriver(C#), Selenium IDE, Nightwatch,Appium, Jira, TFS, ZAP, Fiddler, Jmeter, Jenkins, Selenium Webdriver. I am also ITIL certified.

Leave a Reply