DEV Community

Cover image for E2E Testing of excel file downloads with cypress

E2E Testing of excel file downloads with cypress

Vivek Nayyar on April 07, 2020

Recently while working on a project, I had to create a functionality where users can download an excel file consisting of some data. In this proce...
Collapse
 
rolkool profile image
rolkool • Edited

Unfortunately, this will not work on headless mode.
Clicking on download button does not have any effect. Neither the file appears on browser footer nor it is saved anywhere.

As a result, such tests have to be skipped when run on CI, unless there is a workaround.

Collapse
 
mythily1426 profile image
Mythily

hi, any luck running these tests in CI? have you gt any solution?

Collapse
 
suprabha_chaudhary_fb8ad0 profile image
Suprabha Chaudhary

This piece of code does not work for me even after adding below in command.js
Cypress.Commands.add("parseXlsx", (inputFile) => {
return cy.task('parseXlsx', { filePath: inputFile })
});

Getting error "cy.parseXlsx is not a function" is not a function
Can someone help . Thanks heaps

Collapse
 
tuly12 profile image
tuly12

i tried this code buy inside the spec file the parseXlsx wasn't recognized - any idea why?

Collapse
 
adrianflutur profile image
Adrian Flutur

Hi. Same for me. I'm very new to Cypress. Going out an a limb here, but shouldn't parseXLSX also be added to the cypress commands? Also how would you go about testing data on an excel file containing multiple sheets?

Collapse
 
tuly12 profile image
tuly12

another issue,
i finally succeeded to run the code but it fail with the following error :
fs.readFileSync is not a function

i read that it because :
fs will not work in the browser. This is by design as to protect your filesystem from potential security threats.

in case it is true, how the demo show that it is possible?

Thread Thread
 
prabhat66in profile image
Prabhat66in • Edited

you need to add this in command.js file for above code to work
Cypress.Commands.add("parseXlsx", (inputFile) => {
return cy.task('parseXlsx', { filePath: inputFile })
});

Collapse
 
abhimassive profile image
Abhi

Anti-pattern, and very bad practice to arbitrarily wait for cy.wait(2000);
What if its a large file of 20MB or you are on a slow internet connection?
Will you wait for 60 seconds then?