我必须为一个包含选择文件对话框的电子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 :该值为空
我是幽灵党的新手。我是不是遗漏了什么?
更新: choose文件元素的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>发布于 2019-03-27 18:48:12
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并测试此方法是否有效。
https://stackoverflow.com/questions/55373927
复制相似问题