'Cypress - How to verify if a file is downloaded?
I would like to check that a file is downloaded as part of my test. I only need to confirm that the file is downloaded after clicking a button. I have no need to read the file and its contents. All the files I am downloading are zips, not sure if that makes them harder to read?
it('Initiate download', () => {
  cy.get('[id="download-button"]')
    .should('be.visible')
    .click()
 });
 it('Verify the downloaded file', () => {
   cy.readFile('/Downloads/fileName.zip')
     .should('exist')
 });
							
						Solution 1:[1]
You can try this
const path = require("path");
it('Verify the downloaded file', () => {
   const downloadsFolder = Cypress.config("downloadsFolder");
   cy.readFile(path.join(downloadsFolder, "fileName.zip")).should("exist");
});
    					Solution 2:[2]
I also ran into the same issue but got resolved by using a double backslash for the download folder path and this resolved my issue
it('Verify the downloaded file', () => {
   cy.readFile('cypress\\Downloads\\fileName.zip')
   .should('exist')
 });
    					Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Husnul Aman | 
| Solution 2 | shreyas | 
