3

I have a web site written in Angular and I'm trying to do end-to-end testing using Protractor. The website has a "add button", that opens "choose file dialog box". I want to be able add a file from protractor, but it doesn't upload the file or closes the dialog box.

I tried to create a .exe file that controls the dialog box via (autoIt) and it works fine (when the dialog box pop up i run the .exe and everything is working fine). However, I don't understand how to tell the protractor to launch an .exe after the dialog box appears.

 var path = require('path');
 it('should upload a file', function() {
     var fileToUpload = '...\folder\xxx.txt',
     absolutePath = path.resolve(__dirname, fileToUpload);
     $('#uploadButton').click();
     $('input[type="file"]').sendKeys(absolutePath);
 });

var exec = require('child_process').execFile;
var fun = function() {
    console.log("fun() start");
    exec('c:\\Upload_Nonce.exe', function(err, data) {  
        console.log(err)
        console.log(data.toString());                       
    });  
}
fun(); 
XAMPPRocky
  • 3,160
  • 5
  • 25
  • 45
Oded Kessler
  • 131
  • 2
  • 2
  • 12

1 Answers1

1

You can't control windows dialog boxes with Protractor since it uses webdriver.

The code above will not enter the file path into the windows dialog box but rather it is sending the absolute file path directly to the file upload element on the page.

If you remove the $('#uploadButton').click(); it should work, however if the website you're testing on doesn't allow this type of injection, you may need to write a script to manually expose the element.

See How to upload file in angularjs e2e protractor testing for more information.

Community
  • 1
  • 1
KCaradonna
  • 760
  • 6
  • 13
  • Hi I allready made an exe file with aoutoit , that takes focus on the "select file window" and chose a file that I want and closes the window (and it's working great ) . I just need to understand how do I tell the web site (via protractor ) to click on the button and run the exe file .what do i need to write , do I need to write asynchronic run exe command via protractor - really need help !!! – Oded Kessler Mar 25 '16 at 15:48