3

Tools I'm using: Protractor 3.3.0, Jasmine 2.4.1, Selenium Standalone Server

As the title suggests -

I'm creating a test that navigates to a certain page and then clicks an 'upload file' button. This then triggers the browsers File Upload Window (the one similar to windows explorer). The issue is finding out if there's a way to manipulate that window itself using JavaScript as per Protractor/Jasmine.

I did something similar a while back using Java, in doing so I did a: find all windows, switch to the top of the stack, keyboard input to tab into the input field, paste from clipboard, and then keyboard enter to submit it.

Problems I'm currently having with the above solution is that doing a find all windows only yields the current browser window and NOT the upload file window.

I'm aware that there's a java import for javascript through npm, but i couldn't get that working right away and would rather just do something straight from Protractor/Jasmine itself than require a bunch of libraries. If that's my only option then I'll dig a little harder.

I also am aware that I can just inject the file path through the HTML: $('input[type="file"]'.sendKeys(filePath);, but since I'm simulating the users actions I'd much rather prefer to access the Upload Window and perform actions that way to get a more complete test.

Any thoughts/suggestions would be greatly appreciated.

2
  • You can use AutoIT to write script and generate .exe file from au3 file, and send the .exe location something like this: var exec = require('child_process').execFile; exec('C:/Users/FileToUpload.exe');
    – Nick
    Jun 3, 2016 at 21:48
  • You should not test upload window of browser. Thats not feature of application, thats browser feature. Do not test browser.
    – Xotabu4
    Jun 7, 2016 at 8:02

1 Answer 1

-1

There is easier way, without AutoIt. Use FileDetector feature of selenium. Here is example how i using it (require works only with node 5.X ). For me it works perfectly with selenium grid, localruns, Saucelabs.

var FileDetector = require('selenium-webdriver/remote/index.js').FileDetector;
browser.setFileDetector(new FileDetector());

$('css hidden upload input field').sendKeys(filePath).then(function () {
     console.log('Uploading file:', filePath);
});
// File upload could take a lot of time. Try to use as small file as possible.
// Here you should add browser.wait() with your condition that will indicate that upload finished, so you can continue test flow.

Check this question also - Remote File Upload Protractor test

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.