angular - 使用量角器上传文件不起作用
问题描述
我正在尝试使用量角器在 e2e 测试中将文件上传到 Web 表单。文件未上传,输入字段为空。
这是代码:
it('should uploaded', ()=>{
const fileToUpload = '../src/files/somefile.csv';
const path = require('path');
const remote = require('selenium-webdriver/remote');
browser.setFileDetector(new remote.FileDetector());
const absolutePath = path.resolve(__dirname, fileToUpload);
const fileElem = await element.all(by.css('input[type="file"]')).get(0);
fileElem.sendKeys(absolutePath);
// except input file to be not empty
});
路径正确且文件存在于该路径中。没有错误发生。我只是在浏览器上看到输入字段为空。怎么了?为什么没有上传?
解决方案
最后,我找到了解决方案。问题是输入字段需要一些时间才能出现在屏幕上(有一个动画来完成)。所以,为了让它正常工作,我添加了这个:
const EC = protractor.ExpectedConditions;
browser.wait(this.EC.presenceOf(fileElem.get(0)), 5000);
推荐阅读
- java - 无法使用我的 procfile 更改编码
- angular6 - matTextareaAutosize 在 Angular Material 6.4.2 中不起作用
- vba - 如何使用 VBA 删除 word 文档中的空白页?
- java - 使用 throw 语句实现 try-catch 块
- c++ - Boost Spirit QI :在替代函数内具有序列的元组上的自动规则推导
- docker - 我可以告诉 dockerfile 将文件写入主机吗?
- vue.js - Vue.js 2 过滤器不适用于数据表
- vuejs2 - 如何将方法动态添加到 Vue 组件
- c - 当 EPOLLHUP 看起来足够时,为什么我们还需要 EPOLLRDHUP?
- reactjs - 没有路由匹配时如何重定向?