In the mabl Trainer, you can combine file upload steps with assertions to ensure your web application is handling file upload interactions as expected. File uploads are added to your mabl workspace for future test editing and cloud runs, and you can access them by going to Configuration > File Uploads in the app.
Read on to learn more about uploading files to your web app.
Keeping your data safe
Just like other data in your workspace, file uploads are encrypted using industry-standard best practices for key strength and key management. File uploads remain in the mabl cloud until you choose to delete them.
Training a file upload step
File upload steps require your application to have a file type input element in the page’s HTML. This is the standard HTML element for file selection, and it’s what mabl interacts with to set the file input. If your application doesn’t have this element, file upload steps won’t work.
To get started, open the mabl Trainer and navigate to the page in your application where the file upload step needs to occur. Make sure the record button is on.
- Click on the “file upload” or “choose file” button in your application. mabl intercepts the file picker and opens the file selection modal.
- In the mabl file picker menu, choose a source. If the page's file input accepts multiple files, you can build a list of files to upload, from any of the supported sources:
- Your computer: browse your local disk and upload the file to your workspace.
- Downloaded in this test: reuse a file that your test captured from an earlier download in the same test. mabl tracks the download as a file variable, so replay picks up the right file even when its name changes between runs.
- Workspace upload: choose a file you have already saved to your workspace uploads.
- File variable: use a file uploaded to the test as a data-driven variable. Select a specific file variable, or type a filename template that combines text with mabl variable syntax to choose the file at runtime. File variables may also be overridden by shared file downloads from an earlier test in the plan.
- mabl automatically records a step that sets the file input: “Set file input to {name-of-file}”.
- Record the action to submit the file upload in your application. For example, click on the “submit” button.
- Create an assertion to confirm that the upload was successful. This assertion will depend on what happens in the application after a successful file upload.
File requirements
By default, file uploads are supported up to 100 MB.
The maximum filename limit is 255 ASCII characters. However, if the filename includes non-ASCII characters the limit may be as low as 84 characters, depending on character encoding and the 255 bytes available for filenames.
Recording custom file upload steps
If, for some reason, the Trainer doesn't record a "set file input" step when you select a file, try creating a custom file upload step with a Playwright locator, CSS, or XPath:
- In the Trainer, add a custom find step: Add step > Find Elements.
- Enter the locator that targets the file input. For example,
xpath=//input[@type='file']. - Select Set file input as the action.
- Choose the file you want to upload from the dropdown.
If the page has multiple file input elements, you may need a more specific XPath expression to target the correct one, for example: xpath=//input[@type='file' and @name='document'].
Updating file input
To update the file input, click on the pencil icon next to the recorded file upload step. You can choose a new file input from the dropdown.
For steps that support uploading multiple files, the list arrives pre-filled with the files the step already holds, from which you can add or delete files as needed.
Data-driven file sources
When you select File variable as the file source, the file doesn't have to be fixed when you record the step. mabl can decide which file to upload when the test runs, from either of these sources:
- Shared file variables downloaded in an earlier test and shared with the current test.
- A filename template that resolves to the name of one of the test's file variables
The reference must resolve to a file variable the test has at runtime. If it doesn't, the step fails with the message "file upload reference was not found." For a template, check that it resolves to a name you gave a file variable. For a shared download, check that the earlier test ran first and had Shared variables enabled.
Upload a file that an earlier test downloaded
A file that one test downloads can be uploaded by another test in the same plan. Use shared variables to validate round trip journeys, for example exporting a report in one test and re-importing it in another.
-
Name the file in the downloading test. Open the download step and fill in Save as file variable, for example
exportedReport. Name it deliberately: if you leave the field blank, mabl names the variable for you, and the uploading test has nothing to match. - Share that test's variables. On the downloading test's details page, toggle on Shared variables. See sharing variables between tests.
- Add a matching file variable to the uploading test: {x} > Manage variables > Data-driven variables > New file variable. Give it the same name, and upload any file as a placeholder for training. Names are case sensitive.
- Add or edit a file upload step, select File variable as the file source, and select the placeholder variable.
- Order the plan so the downloading test finishes first, using a sequential stage or separate stages.
During training and ad hoc runs, the step uploads the placeholder file. During plan runs in the cloud, the file from the downloading test replaces it.
Requirements and limitations
- Only downloaded files travel between tests. A file you upload to a test as a data-driven variable stays with that test.
- Both tests must run in the same plan, and the downloading test must run first.
Select a file variable by name at runtime
If your test needs to upload a different file depending on the situation, you can select the file variable by name when the test runs. Combine literal text with mabl variable syntax to build a filename template, and mabl resolves the template to a file variable at runtime.
- Choose the variable that holds your runtime value. This can be a DataTable scenario value, a value extracted from the page, or a value from an API response.
-
Create a file variable for each expected value, naming each one so it matches your template. For example, for a variable named
country_code, you could name the file variablesusers_us,users_ca, andusers_fr. -
Add or edit a file upload step, select File variable as the file source, and type the filename template in the Variable field instead of picking a specific variable:
users_{{@country_code}}.
When the test runs, the step uploads whichever file variable the template resolves to: users_ca when the page shows ca, users_fr when it shows fr.
Because mabl matches file variables by name, give them names that follow a consistent pattern, such as a fixed prefix followed by the runtime value.
Using conditionals instead
If your files aren't named on a predictable pattern, use conditionals to evaluate the scenario and set the input to the appropriate file. This approach needs a condition for every file, so a filename template is usually simpler when the names can follow a convention. The following screenshot shows test steps that upload a different file depending on the DataTable scenario:
Uploading a different file according to the DataTable scenario
Limitations
Keep in mind the following limitations for file uploads in the mabl Trainer:
- No support for drag-and-drop file selection
- Selecting a file from a variable at runtime is supported for browser upload steps only, not for mobile tests or API request bodies