Appearance
I.upload()
Uploads a file to a file input element.
I.upload() attaches the file directly to an <input type="file"> element, without opening the native file picker dialog.
WARNING
Tests must not attempt to open the native file dialog. It cannot be automated or dismissed and will cause the test to hang.
Usage
javascript
I.upload(fileInputElement: string, filePath: string)Parameters
| Parameter | Type | Description |
|---|---|---|
fileInputElement | string | Target file input element (by visible text, CSS selector, or XPath). |
filePath | string | Path to the file to upload. Can be relative to the current test file or from the project root. |
Examples
INFO
You must add the file to the test project before using it with I.upload().
Upload a file
js
I.upload("#resume-upload", "documents/resume.pdf")
I.click("Submit")This uploads a file located at "documents/resume.pdf" from the project root to the "#resume-upload" file input field.
Uploading a downloaded file
You can upload a file that has been downloaded during the test.
Downloaded files are saved to a virtual downloads folder at //downloads.
js
I.upload("Supporting documents", "//downloads/fileA.pdf")This will upload "fileA.pdf" if it exists in the Downloads folder.
Alternatively, you can access the list of downloaded files metadata via the UI.Downloads.files property, and use the .path property of the selected file.
js
I.upload("Supporting documents", UI.Downloads.files[0].path)This will upload the first downloaded file.