How to Test File Downloads
Test file downloads in Endtest: trigger downloads, capture the most recent file, and assert on PDF, CSV, JSON, or image file contents.
Introduction
In a Web Test, you can add steps to verify file downloads.
After you trigger a file download, you can extract information about the file in variables.
Then, you can use those variables in other steps, such as Assertions and If Statements.
Details
You can extract information about a downloaded file by using these methods from the Set Variable action:
Extract Name of Most Recent Downloaded FileExtract Size of Most Recent Downloaded FileExtract MIME Type of Most Recent Downloaded FileLink to Most Recent Downloaded File
You can then use the resulting variables in later steps, such as Add Assertion → Variable Assertion.
After you've extracted the information into variables, you can verify the values from those variables by using the Variable Assertion method from the Add Assertion action.
You can also clear the Downloads directory by using the Clear Downloads Directory method from the Miscellaneous action.
Testing file content
The Link to Most Recent Downloaded File method from the Set Variable action uploads the downloaded file from the machine that executed the test.
The resulting variable contains a link that can be used to open or download that file.
If the file type can be displayed directly in the browser (such as .txt, .jpg, .mp4, etc.), you can use a Go to URL step to open and view the file in the browser.
Methods from the Endtest Utilities API can also be used to convert files to HTML (for example convertCSVtoHTML or convertPDFtoHTML). This makes the content easier to view and validate in the browser.