To help you cover end-to-end testing scenarios, the mabl Trainer detects and automatically adds assertions for file downloads from your web app. By default, the Trainer asserts against the name of the downloaded file, but you can also edit the assertion to validate the file contents or other metadata.
This article explains how to work with download assertions in the Trainer, including how to…
A download assertion step in the Trainer
Assert on file metadata
To assert on file metadata, including filename, file type, and file size, click on Edit assertion. Alternatively, click on the edit pencil for the download assertion step.
Dynamically generated filenames
If your application creates a dynamically generated filename for the file download, you may try one of the following workflows to assert that the file has downloaded:
-
Use mabl variable syntax - if you know how the filename is generated, or if you can extract the filename from the page before downloading, store the filename in a variable and assert against that filename using mabl variable syntax, for example
{{@filename}}. - Remove the filename assertion - if you do not know what the filename will be before downloading it, remove the filename from the download assertion and assert against other attributes, such as the MIME type or file size.
Using mabl variable syntax in a download assertion
Limitations with filename assertions
- Download assertions do not currently support partial string matching or the use of wildcards (
*) within filenames. - Download assertions aren’t supported for filenames that contain accented characters.
Assert on file contents
You can also validate the content of downloaded files with GenAI Assertions. Most common file types are supported, including spreadsheets, images, PDFs, audio, and video.
Early access
GenAI Assertions for file downloads are currently available in early access for all mabl customers and trial users via the Labs page.
Prior to general availability, changes to the feature may be made without notice.
To assert on the contents of a downloaded file, edit the download assertion step. Provide a natural language prompt that describes what you would like to validate. To review file contents, click on View file. When you are ready to test your assertion, click on Test assertion.
The first time you test the assertion, mabl generates assertion criteria. These criteria are sent with the assertion description to the LLM to provide a consistent set of criteria to evaluate as part of your assertion. If you iterate on the assertion description, mabl updates the assertion criteria to reflect the current state of the description.
Testing an GenAI Assertion for a file download
Screenshots and viewports
When asserting against a file download, GenAI Assertions include both the contents of the downloaded file and a screenshot of the page it was downloaded from. With the page screenshot, you can create validations on data across the file and the app. For example, you could assert that the file data from a spreadsheet aligns with the product information that is visible on the current page.
Keep in mind that the screenshot only includes the portion of the page that is currently visible in the viewport. If you assert on something that isn’t fully visible in the viewport, any parts of the page that are off-screen will not be included in the evaluation. To resize the window, add a “set viewport” step before the assertion: + (Add step) > Set viewport.
Execution limits
GenAI Assertions are unlimited during training so that you can iterate on your assertion as much as you need. During execution, however, keep in mind the following limitations:
- Limit per test: GenAI Assertions are limited to 30 per test.
- Performance tests: GenAI Assertions will fail when run within the context of a performance test.
Replay download assertions
To replay a download assertion in the Trainer, move the Trainer cursor to just above the click step that triggers the download and click play. The Trainer automatically elides numbers that are added to repeatedly downloaded files so that foo (1).zip becomes foo.zip for the assertion comparison. This feature enables replay testing without need of manual file cleanup.
Due to Chrome limits, you may only download a file 100 times. If you replay a download step in the mabl Trainer more than 100 times, Chrome automatically opens a save file modal for every additional download, preventing further replay of the download step. To restore replay functionality, remove the downloaded files from your machine.
Limitations
Note the following limitations when downloading files in your test:
- File assertions are supported for recorded click steps. Click steps that use CSS or XPath do not trigger a download assertion.
- The Trainer cannot validate multiple downloads in parallel.
- mabl automatically cleans up downloaded files at the end of each training session a test execution. For this reason, it is not possible to manually inspect the content of downloaded files outside of a training session.
- Download assertions wait up to 30 seconds before timing out. If the download takes longer than the default 30-second download timeout, add a wait step before the download assertion.
If any of the following capabilities are important to your team, please let us know in the mabl Product Portal.