Protractor - upload file/ running exe via protractor

情到浓时终转凉″ 提交于 2019-12-06 06:43:57

问题


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

回答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.



来源:https://stackoverflow.com/questions/36182407/protractor-upload-file-running-exe-via-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!