3

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.

3
  • 2
    This is how I do it: stackoverflow.com/questions/21305298/… Commented Jun 18, 2014 at 3:10
  • @AndresD, I did go thru your solution but we have a specific use case of using ngflow. Thanks for letting us know. Commented Jun 20, 2014 at 6:22
  • Did you try sending the Enter key? Commented Aug 24, 2014 at 18:11

2 Answers 2

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();
});
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.