How to test a file download or a CSV export
How to test file download in four checks. A file arrived, it is the type the button names, it isn’t empty, and it holds the rows the page showed. Open the file.
To test a file download, open the file. A click that starts a download proves a file arrived, and that is the weakest of four checks. The file must be of the type the button names, it must not be empty, and it must hold what the page showed: the same rows, the same numbers. All four of our practice app’s exports start a download and answer 200. Two of them are broken.
Here is how to test a file download or a CSV export properly, with what we found in ours.

How to test file download: the four checks
Run them in this order. Each is harder than the one before, and each catches what the previous one lets through.
1. A file arrived. Press the button and something lands in the downloads folder. This catches a dead link and a button that opens a page where a file should be. It catches nothing else.
2. It is the type the button names. “Export JSON” must hand over JSON. Don’t trust the file’s name, and don’t trust the type the server announces. Our broken export is called report.json and is announced as JSON. Opened, it is a web page: the app’s own error page, sent with a success status and a download header. Anything that reads that file as JSON fails on the first character.
3. It isn’t empty. Our “Export archive CSV” downloads a file of zero bytes with the right name and the right type. A quick look in the downloads folder shows a file called archive.csv, and a tester moves on.
4. It holds what the page showed. This is the check that needs the page beside the file.
Verify the downloaded file against the page
Our reports page shows a table, and its export links sit under it.

The CSV it exports:
name,amount
Alpha Supplies,"1,200"
Beta Tools,"340"
Gamma Parts,"75"
Compare them the way you would check a bank statement:
- Count the rows. Three on the page, three in the file (plus the header line). An export that silently stops at a page size, or at the first odd character, shows up here.
- Check the first row and the last row by name. The last row is the one that goes missing. Our practice app has a switch for exactly that fault, an export that leaves out the final row, and our own test suite has to catch it. With the switch on, the file has a header, Alpha Supplies and Beta Tools, and looks perfectly healthy unless you know Gamma Parts should be there.
- Check one number. 1,200 on the page,
"1,200"in the file. - Check the columns. The same ones, in the same order, with headings a person can read.
Write those into the expected result of the test case: “three rows; the last is Gamma Parts, 75”. “The export works” is not something a file can be compared with.
Test a CSV export: the comma, the accent, the zero
Three things break CSV files that pass the row count.
A comma inside a value. Look at "1,200" above. The amount contains a comma, and the comma is also what separates columns. Our export puts the value in quotes, which is correct. An export that doesn’t writes Alpha Supplies,1,200, and a spreadsheet reads three columns in that row and two in the others. Put a comma in one of your test values on purpose. And a quote. And a line break in a note field.
An accent. Put é in a name, export, and open the file in the spreadsheet program your customers use, not in a code editor. If it shows as two odd characters, the file’s encoding and the program disagree. This one is invisible to a test that reads the file as text, because the test reads it correctly.
A leading zero. A postcode of 01234 or a phone number. The file may be right and the spreadsheet may still drop the zero when it opens it. Decide whether that is yours to solve (your customer opens your file, so the fault looks like yours).
One more for exports that people open in spreadsheets: a value that starts with =. A spreadsheet may run it as a formula. If your users can type the values that end up in other people’s exports, that deserves a look from someone who does security.
What else to try
- The export with a filter on. Search or filter the list, then export. Does the file hold the filtered rows or all of them? Either can be right. It has to be what the page suggests, and the same every time.
- The export of nothing. An empty list. A file with only the header line is a good answer. An error page saved as a CSV is the bug from check 2 again.
- A large export. Many rows. The wrong answers are a timeout and a file cut off in the middle, and the row count catches the second.
- Someone else’s export. Log in as a second user and open the first user’s export address. It is the IDOR check for files, and an export holds a lot of data in one request.
E2E test of a file download: where it goes wrong
Automating this, three traps:
- Asserting on the status. All of the above answered 200. That is a pass that checked nothing.
- Asserting on the file name.
report.jsonwas the right name. - Reading the type from the header. It said JSON. Read the first bytes of the file itself: a PDF starts with
%PDF, a web page starts with<.
And clean up: downloaded files pile up on whatever machine runs the tests.
How EveryRole tests a download
EveryRole treats a control that downloads a file as its own kind of stop: a link to a file, or a button whose words name a file type, like “Export CSV”.
Its main case there is exactly checks 1 to 3: it downloads a file of the type its button names, and the file isn’t empty. The type is read from the file’s own bytes. On our practice app that turns “Export JSON” and “Export archive CSV” into Broken, where a status check stays green.
The extra case, it holds what the list showed, is check 4. It is off until you turn it on, and it applies where the button names a text type such as CSV.
The file lands in a folder of the run’s own, deleted when the run ends. What it doesn’t do is open the file in a spreadsheet program, so the accent and the leading zero are still worth a few minutes of a person.


