With file variables, you can reuse the same file across upload steps. On the latest version of the Desktop App, upload steps now support combining literal text with mabl variable syntax to select a file variable. With this capability, you can set up your tests to upload a different file depending on dynamic, data-driven values at runtime, such as a DataTable scenario value, API response, or data on the page.
Try it out
-
Identify your dynamic variable & filename template: Choose the variable that holds your runtime value (e.g. from a DataTable, API response, or page data) and decide how to combine it with fixed text into a filename template. For example, with a DataTable variable named
docTypeyou could create the filename template{{@docType}}File. -
Create the file variables: In the Trainer, create data-driven file variables for each expected value, making sure to match the filename template. For example,
invoiceFileandreceiptFile. -
Configure the upload step: Add or edit a file upload step and select File variable as the file source. In the Variable field, type your filename template (e.g.
{{@docType}}File) instead of picking a static variable.
At runtime, mabl resolves the filename template and uploads the corresponding file variable. If the filename template resolves to a name that is not a file variable in the test, the step fails with the message "file upload reference was not found."
Example
Suppose your test needs to upload a specific user file that matches the country code displayed on the page. In this situation, you could create a variable from the element property that displays the country code, and name it country_code.
Then add file variables for each country code your test might encounter, naming each one so that the country code follows a fixed users_ prefix, for example users_us, users_ca, and users_fr. Those names are what the filename template users_{{@country_code}} will resolve to later on when you create the file upload step.
In your file upload step, set the file source to File variable and type users_{{@country_code}}.
When the page shows the country code ca, the step uploads the users_ca file variable. When it shows fr, the same step uploads users_fr.
Data-driven file selection works for browser upload steps. Choosing a file from a variable in mobile tests or API request bodies is not supported yet.