In this blog, we will 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.
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.
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.
Step 4: Open Cypress to create a Cypress folder structure
Finally, the above command will open Cypress.
Step 5: Write the following code in example.json
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.