We are using ngFlow to do file uploads in our application. We use protractor for our testing. We have multiple test case conditions to be tested like file format not supported, max size etc. What is the best way to select files using protractor? We are able to click the button to upload the file, but we don't have any control on the system file explorer. We are able to send keys to input type file but we don't know how to call submit on that as we are not a button inside of a form/ using a form.
Asked
Active
Viewed 4,362 times
3
-
2This is how I do it: http://stackoverflow.com/questions/21305298/how-to-upload-file-in-angularjs-e2e-testing/21314337#21314337 – Andres D Jun 18 '14 at 03:10
-
@AndresD, I did go thru your solution but we have a specific use case of using ngflow. Thanks for letting us know. – Pradeep Mahdevu Jun 20 '14 at 06:22
-
Did you try sending the Enter key? – boatcoder Aug 24 '14 at 18:11
2 Answers
1
You need to inject the path of your file into your input.
var path = require('path');
it('should upload file', function() {
var fileToUpload = '../path/foo.txt',
var absolutePath = path.resolve(__dirname, fileToUpload);
$('input[type="file"]').sendKeys(absolutePath);
$('#uploadButton').click();
});

rbinsztock
- 3,025
- 2
- 21
- 34
0
A good approach here will be to use superspawn to run a batch file or any script that works on your desired operating system. You can read about superspawn here-https://www.npmjs.com/package/superspawn

Rahul Vig
- 716
- 1
- 7
- 24