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

2023-09-13 03:18:05 作者:随性

我已经写在角一个网站,我试图做终端到终端的测试用量角器。该网站有一个添加按钮,打开选择文件对话框。我希望能够从添加一个量角器文件,但它不会上传文件或关闭对话框。

我试图创建一个通过(AutoIt的)控制对话框 .exe文件文件和正常工作(当对话框弹出我运行 .exe文件和一切工作正常)。但是,我不知道如何告诉量角器发动出现的对话框中 .exe文件之后。

  VAR路径=要求('路径'); 它('应上传文件',函数(){     VAR fileToUpload ='... \\文件夹\\ xxx.txt',     absolutePath = path.resolve(__目录名,fileToUpload);     $('#uploadButton')点击()。     $('输入[类型=文件]')的SendKeys(absolutePath); }); 

  VAR EXEC =要求('child_process')的execfile。VAR乐趣=功能(){    的console.log(有趣()启动);    EXEC('C:\\\\ Upload_Nonce.exe',函数(ERR,数据){        的console.log(ERR)        的console.log(data.toString());    });}有趣的(); 

解决方案 量角器

您无法控制Windows对话框与量角器,因为它使用的webdriver。

在code以上不会输入文件路径到Windows对话框,而是直接发送到页面上的文件上传元素绝对文件路径。

如果您删除 $('#uploadButton')点击(); 它应该工作,但是如果你正在测试的网站不允许这种注射的类型,你可能需要编写一个脚本来手动曝光的元素。

请参阅How上传的angularjs E2E量角器测试文件的详细信息。

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

解决方案

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.