typescript - 在 Spectron 中选择和上传测试文件
问题描述
我必须为包含选择文件对话框的电子 GUI 编写测试。我无权访问 GUI 的实现。
我写过
await app.client.chooseFile('//*[@id="import-file"]/form/div/div/div[1]/input', path.join(__dirname, '..','..','..', 'Fahrtzeit.xlsx'))
.catch(function (error) {
console.log(error);
}).getValue('//*[@id="import-file"]/form/div/div/div[1]/input').then(function (val) {
console.log("value is :"+val);
});
我得到一个控制台输出
value is :
值为空
我是光谱仪的新手。我错过了什么吗?
更新:选择文件元素的 DOM 是
<div _ngcontent-c9="" class="mat-form-field-flex"><div _ngcontent-c9="" class="mat-form-field-infix"><input _ngcontent-c9="" class="mat-input-element unit-input ng-untouched ng-pristine ng-valid" formcontrolname="fileDisplay" readonly="" type="text" ng-reflect-name="fileDisplay" title="Auftragsdatei auswählen"></div><button _ngcontent-c9="" class="btn btn-link filepicker-btn unit-filepicker"><ui-icon _ngcontent-c9="" class="filepicker-icon" iconname="a_ic_attach_file" _nghost-c5="" ng-reflect-icon-name="a_ic_attach_file" id="import-file-icon"><div _ngcontent-c5="" class="a_ic_attach_file" ng-reflect-ng-class="a_ic_attach_file"></div></ui-icon></button><div _ngcontent-c9="" class="mat-form-field-underline"></div></div>
解决方案
it('Should upload a file',async ()=>{
let toUpload = path.join(__dirname, '..', '..', 'fixtures', 'Fahrtzeit.xlsx')
await app.client.chooseFile('//*[@id="import-file"]/form/div/div/div[1]/input', toUpload);
let val =await app.client.getValue('//*[@id="import-file"]/form/div/div/div[1]/input');
// Do asserts and test the **val**
})
参考:http: //v4.webdriver.io/api/utility/chooseFile.html
只需控制台 val 并测试它是否有效。
推荐阅读
- typescript - 合并 Socket.IO 的 TypeScript 接口声明不起作用
- reactjs - 尝试“读取”firebase 数据并将其呈现在 ReactJS 上
- reactjs - 定义不带样式组件的 CSS 变量
- django - 注释来自过滤的相关对象的值——案例、子查询或其他方法?
- idl - 在 IDL 中使用 IDLgrClipBoard 时,MacO 能否正确显示图像?
- angular - 延迟 *ngIf 语句
- sql - 需要通过连接 Oracle DB 中的多个表来创建空表
- html - 在某些缩放级别将绝对定位的 div 对齐 1px
- javascript - 如何将全日历视图设置为在当前日期前 1 周开始?
- html - 覆盖内容的动画