测试文件选择并在斯派克中上传



我必须为包含选择文件对话框的电子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 并测试这是否有效。

最新更新