简体   繁体   English

量角器 - 通过量角器上传文件/运行exe

[英]Protractor - upload file/ running exe via protractor

I have a web site written in Angular and I'm trying to do end-to-end testing using Protractor. 我有一个用Angular编写的网站,我正在尝试使用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). 我尝试创建一个.exe文件,通过(autoIt)控制对话框,它工作正常(当弹出对话框我运行.exe ,一切正常)。 However, I don't understand how to tell the protractor to launch an .exe after the dialog box appears. 但是,我不明白如何在对话框出现后告诉量角器启动.exe

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

You can't control windows dialog boxes with Protractor since it uses webdriver. 您无法使用Protractor控制窗口对话框,因为它使用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. 上面的代码不会将文件路径输入到Windows对话框中,而是将绝对文件路径直接发送到页面上的文件上传元素。

If you remove the $('#uploadButton').click(); 如果删除$('#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. 有关详细信息,请参阅如何在angularjs e2e量角器测试中上传文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM