加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何上传文件在angularjs e2e量角器测试

发布时间:2020-12-17 08:58:20 所属栏目:安全 来源:网络整理
导读:我想使用angularjs e2e测试测试文件上传。你如何在e2e测试中这样做?我通过咕咕业务运行我的测试脚本。 这是我怎么做: var path = require('path');it('should upload a file',function() { var fileToUpload = '../some/path/foo.txt',absolutePath = path
我想使用angularjs e2e测试测试文件上传。你如何在e2e测试中这样做?我通过咕咕业务运行我的测试脚本。
这是我怎么做:
var path = require('path');

it('should upload a file',function() {
  var fileToUpload = '../some/path/foo.txt',absolutePath = path.resolve(__dirname,fileToUpload);

  element(by.css('input[type="file"]')).sendKeys(absolutePath);    
  element(by.id('uploadButton')).click();
});

>使用路径模块解析要上传的文件的完整路径。
>设置输入type =“file”元素的路径。
>点击上传按钮。

这不会在firefox上工作。量角器会抱怨,因为元素不可见。要在firefox中上传,您需要使输入可见。这就是我所做的:

browser.executeAsyncScript(function(callback) {
  // You can use any other selector
  document.querySelectorAll('#input-file-element')[0]
      .style.display = 'inline';
  callback();
});

// Now you can upload.
$('input[type="file"]').sendKeys(absolutePath);    
$('#uploadButton').click();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读