Test Overview
This test checks if a file download starts correctly when the user clicks the download button. It verifies the file exists in the download folder after the click.
This test checks if a file download starts correctly when the user clicks the download button. It verifies the file exists in the download folder after the click.
describe('File Download Verification', () => { it('should download the file when clicking the download button', () => { cy.visit('https://example.com/download-page'); const downloadsFolder = Cypress.config('downloadsFolder'); cy.get('#download-btn').click(); const downloadedFileName = 'sample.pdf'; const downloadedFilePath = `${downloadsFolder}/${downloadedFileName}`; cy.readFile(downloadedFilePath, { timeout: 15000 }).should('exist'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.com/download-page' | Browser shows the download page with a download button having id 'download-btn' | — | PASS |
| 3 | Finds the download button using selector '#download-btn' | Download button is visible and enabled | Check that element '#download-btn' exists | PASS |
| 4 | Clicks the download button | Browser initiates file download of 'sample.pdf' | — | PASS |
| 5 | Reads the downloaded file 'sample.pdf' from the downloads folder | File 'sample.pdf' is expected to be present in the downloads folder | Verify file exists at path `${downloadsFolder}/sample.pdf` | PASS |
cy.downloadFile('https://example.com/report.pdf', 'cypress/downloads', 'report.pdf')
.then(() => {
cy.readFile('cypress/downloads/report.pdf').should('exist')
})cy.downloadFile('https://example.com/data.csv', 'cypress/downloads', 'data.csv')
cy.readFile('cypress/downloads/data.csv').should('contain', 'Name, Age')Pass the test and this pattern moves unknown