0

I want to test file uploading with this code, which was found here :

var path = require('path');    

var fileToUpload = '..\\..\\files\\avatarPicture.jpg';
var absolutePath = path.resolve(__dirname, fileToUpload);

var fileElem = element(by.css('input[type="file"]'));

browser.executeScript(
  "arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", fileElem.getWebElement());

browser.executeAsyncScript(function(callback) {
   document.querySelector('input[type="file"]').style.display = 'inline';
   callback();
   });

   $('input[type="file"]').clear().sendKeys(absolutePath);

and there is a WebDriverError:

Failed: File not found: C:\works\project\files\avatarPicture.jpg
  • I already checked the path - it is correct. I can easily open file from command line
  • I try to use both backslashes and slashes. There is still same error.
  • WebDriver version: gecko v0.17.0
  • Windows 10 Pro
  • Everything is working on Chrome, but I need a solution for Firefox.
wojky
  • 78
  • 7
  • https://stackoverflow.com/questions/21305298/how-to-upload-file-in-angularjs-e2e-protractor-testing/21314337#21314337 – Venu Duggireddy Sep 28 '17 at 02:54
  • @VenuDuggireddy ok, so far I know that it is Firefox issue, the file is visible on, for example, Chrome, but still Firefox cannot find that file. – wojky Sep 29 '17 at 09:43

2 Answers2

0

Try this

fileElem.clear().then(function() {
    fileElem.sendKeys(absolutePath);
})
Deepak Tripathi
  • 600
  • 2
  • 4
  • 22
0

Can you try as in this Bug 858 workaround

Venu Duggireddy
  • 786
  • 6
  • 9