How Can I Test A File Download Using Cypress When Running In Chrome How Can I Test A File Download Using Cypress When Running In Chrome google-chrome google-chrome

How Can I Test A File Download Using Cypress When Running In Chrome


Actually I searched alot about it and found thatIt is not possible to run tests in headless mode with browser extensions installed, because the only supported browser in headless mode is Electron, and Electron doesn't support extensions as stated in the documentation.

Running headless Chrome is not supported yet. See this issue: #488https://github.com/cypress-io/cypress/issues/488

And this is a an issue not so old it was tagged in Feb 2019

https://github.com/cypress-io/cypress/issues/832https://github.com/cypress-io/cypress/issues/1235


There are a lot of ways to test this, so it depends. You’ll need to be aware of what actually causes the download, then think of a way to test that mechanism.

If your server sends specific disposition headers which cause a browser to prompt for download, you can figure out what URL this request is made to, and use cy.request() to hit that directly. Then you can test that the server send the right response headers.

If it’s an anchor that initiates the download, you could test that it has the right href property. As long as you can verify that clicking the button is going to make the right HTTP request, there’s nothing else to test for.

In the end, it’s up to you to know your implementation and to test enough to cover everything.


You can prevent the test from hanging by disabling the dialog asking where to save the file. Once you do that chrome will happily download your file and Cypress can continue running your test.

In chrome go to settings->Advanced->Downloads->Ask where to save each file before downloading and make sure it is off.

There are more complicated solutions in the links Apolo provided but this is a quick workaround.