I am using https://github.com/danialfarid/ng-file-upload for file upload. I have to test it so I wrote protractor test case but it not working.
代码
<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>
测试用例
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);
})
我可以上传文件,但它是在 rejFiles 模型而不是 files 模型中接收的,尽管文件格式是正确的。有人可以建议我如何做到这一点吗?
最佳答案
HTML
<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>
测试用例
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);
关于angularjs - Protractor - 如何在测试用例中使用 ng-file-upload 上传文件而不更改代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29384676/