自动化测试时无法上传文件

时间:2015-10-22 14:49:02

标签: html angularjs selenium-webdriver automated-tests protractor

我在自动化测试中一直使用相同的功能上传文件:



        var path = require('path');
         //the file to upload
        fileToUpload,
         //this is variable that inserts the path to find file to upload
        absolutePath = path.resolve(__dirname, fileToUpload);
         //inserts the path
        uploadPathLink.sendKeys(absolutePath);



 我的html中的按钮/链接如下所示:



<button class="btn btn-select" data-bind="click: assosiateLogoImage">
&#13;
&#13;
&#13;

我的html中的上传表单如下所示:

&#13;
&#13;
<form id="uploadForm" action="https://iplan.preview.s3.amazonaws.com/" enctype="multipart/form-data" target="uploadIFrame" method="post">
  <div class="file-input" data-bind="css: {'ie': isIE}">
    <input id="logoFile" type="file" data-bind="event:{ 'change': handleLogoSelection }" name="file">
  </div>
</form>
&#13;
&#13;
&#13;

上传表单会打开然后挂起。我知道该文件的路径是有效的,因为它是我在应用程序的其他部分上传的相同文件,任何想法?

1 个答案:

答案 0 :(得分:0)

问题是我发送了错误元素的绝对路径,应该看起来像这样:

 var path = require('path');
    //the file to upload
    fileToUpload,
        //this is variable that inserts the path to find file to upload
        absolutePath = path.resolve(__dirname, fileToUpload);
    //inserts the path
    $('input[type="file"]').sendKeys(absolutePath);
};