Test Code: index.js
Tested Page: index.html
TestCafe cannot access the browser's Choose File
dialog to emulate file selection. This example shows how to add files to a type="file"
input without browser dialogs.
The sample page includes a <form>
that contains:
- an
<input>
withtype="file"
that stores the selected files - an
<input>
withtype="submit"
that sends the files to the server
During the test the t.setFilesToUpload
method specifies the file paths for the <input type="file">
element. The test clicks the <input type="submit">
to initiate the file upload. Then the test receives a list of uploaded files from the server and checks it with the t.expect.eql
Method.
- Test Structure:
- Fixture.page Method
- Element Identification and Actions:
- Selector Object
- t.click Method
- t.setFilesToUpload Method
- Assertion and Evaluation:
- t.expect.eql Method