← Back to library
Cypressfileintermediatev10+

Download a file and verify content

Trigger a CSV download and assert the file exists with expected content.

1it('downloads the CSV report', () => {
2  cy.visit('/reports');
3
4  cy.get('[data-testid="export-btn"]').click();
5
6  // cy.readFile polls until the file appears (default timeout 4 s)
7  cy.readFile('cypress/downloads/report.csv', { timeout: 8000 })
8    .should('exist')
9    .and('include', 'email,name,role'); // assert the CSV header row
10});
#download#csv#readFile#verify