Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload testing in angular js using protractor

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.

like image 500
Pradeep Mahdevu Avatar asked Jul 05 '26 12:07

Pradeep Mahdevu


1 Answers

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();
});
like image 195
rbinsztock Avatar answered Jul 07 '26 02:07

rbinsztock