量角器 - 如何在不更改代码的情况下在测试用例中使用 ng-file-upload 上传文件?

Anu*_*apu 5 file-upload angularjs protractor

我正在使用https://github.com/danialfarid/ng-file-upload进行文件上传。我必须测试它,所以我写了量角器测试用例,但它不起作用。

代码

<div class="col-lg-12 up-buttons">
     <div ng-file-select="" ng-model="files" ng-model-rejected="rejFiles" class="btn btn-default" ng-multiple="false" ng-accept="'text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'"  ng-model-rejected="rejFiles" tabindex="0">Choose file</div>
</div>
Run Code Online (Sandbox Code Playgroud)

测试用例

it('upload file', function(){   
  var fileToUpload = 'C:/Users/Anusha/Desktop/demo.csv';
  var absolutePath = path.resolve(fileToUpload);
  $('input[type="file"]').sendKeys(absolutePath);
  browser.sleep(1500);
})
Run Code Online (Sandbox Code Playgroud)

测试结果

我可以上传文件,但它是在rejFiles模型而不是文件模型中接收的,尽管文件格式是正确的。有人可以建议我如何做到这一点吗?

Anu*_*apu 4

网页

<div class="col-lg-12 up-buttons">
    <div ng-file-select="" ng-model="files" ng-model-rejected="rejFiles" class="btn btn-default" ng-multiple="false" ng-accept="'*.csv'"  ng-model-rejected="rejFiles" tabindex="0">Choose file</div>
</div>
Run Code Online (Sandbox Code Playgroud)

测试用例

var path = require('path');
var fileToUpload = file_path;
var absolutePath = path.resolve(fileToUpload);
element.all(by.css('input[type="file"]')).then(function(items) {
  items[0].sendKeys(absolutePath);
});
browser.sleep(500);
Run Code Online (Sandbox Code Playgroud)