Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor File Upload with Saucelabs

I'm testing an AngularJS project using protractor. I have an image file upload tests which is working and passing correctly on my local mac machine. However, when I run the same test via saucelabs the test fails.

Saucelabs is having problems finding the file and just opens a dialog box but can't find the file. The file is within my test solution and not in saucelabs. I've looked around on the web for answers but I haven't seen a definitive answer to resolve this particular problem. Below is an example of the code I am using to upload an image file against an application.

var path = require('path');

it('should upload a file', function() {
  var fileToUpload = '../some/path/foo.txt',
  absolutePath = path.resolve(__dirname, fileToUpload);

  $('input[type="file"]').sendKeys(absolutePath);    
  $('#uploadButton').click();
});

Any help or suggestions on how to get the above code to work via Saucelabs will be much appreciated.

like image 761
Chuckos Avatar asked Oct 31 '22 04:10

Chuckos


1 Answers

Have you tried something like:

browser.driver.setFileDetector(new browser.driver.remote.FileDetector); 

According to the protractor issue it's either that or it's not working (bug in Selenium JavaScript bindings or protractor, or version mismatch).

In the same github issue there's also a workaround if the main solution didn't work (tldr: file sharing).

like image 155
Meligy Avatar answered Nov 15 '22 07:11

Meligy