Pradeep Mahdevu
Pradeep Mahdevu

Reputation: 7663

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.

Upvotes: 3

Views: 4366

Answers (2)

rbinsztock
rbinsztock

Reputation: 3195

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();
});

Upvotes: 1

Rahul Vig
Rahul Vig

Reputation: 736

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

Upvotes: 0

Related Questions