Using Excel/CSV data file in Cypress

Using Excel/CSV data file in Cypress

As a QA, who deals with data (read large amounts of data) every single day, we get the data in excel or CSV files. In order for Cypress to read and consume the raw CSV file, we need a csv parser.

This article talks about the csv parser that can be used within Cypress to read the CSV data file.

Step 1 – Install ‘neat-csv’ package

npm install neat-csv@5.2.0

Once installed, make sure your package.json has “neat-csv” added as your dependencies

Step 2- Have the CSV data file in fixtures folder

Let’s say, you have leads information to be read in the data file (leads.csv)

Upload your data file in csv format under fixtures folder

Step 3 – In your testing file (eg: test.cy.js), you need to define a variable to capture the leads data, once it is parsed

Let data;

Step 4 – Now, you are ready to read the leads file using cy.fixture command and then call neatCSV to parse the leads csv file. Once parsed, capture the response and pass it to data variable

Code would be as below:

cy.fixture(leads.csv)

.then(neatCSV)

.then(response => data=response;)