首页 > 解决方案 > 根据承诺的结果在量角器中创建动态它

问题描述

在量角器中,我想实现以下步骤:

  1. 在 appconfigts 中,读取 excel 文件。
  2. 为该excel中的每一行创建sperate它。
   ---start----- 

describe
 {
 let wb= new workbook():
 let configsheet;
 let fileName = 'excel_file.xlsx';
  //read excel and find rowcount 
wb.readFile(fileName).then(function(){
let ws= wb.getWorksheet('Configuration');
let configsheet= ws;
console.log(configsheet.rowCount);
});

for(let i=0;i<configsheet.rowCount;i++){
it('it'+i,function(){
console.log(i);
});
}

});

----end----``

标签: typescriptprotractor

解决方案


虽然理论上可以干预创建/执行块的方式describeit块,但我不明白为什么要以这种方式复杂化。

无论如何,您都可以查看https://github.com/angular/protractor/issues/620#issuecomment-72956621看看是否符合要求。

更新

如果不知道您使用什么 API 来读取 excel 文件,就不可能提出解决方案。

让我给出一些指示:一个 Promise 将来会被实现(或被拒绝)。Promise 对象可让您收到有关它的通知并使用它返回的值做一些事情。

在您的情况下,您正在阅读 Excel,并且 Promise(如果库是有意义的)将为您提供 Excel 中的行,作为成功实现的一部分。话虽如此,您只需要反转您拥有的代码,即不要在创建中使用promise,而是在成功读取excel后it创建sit

readExcel(file, sheetName).then((rows) => {
    for(int i = 0; i <= rows.length; i++){
     it('i:'+i, function ());
    }
})

希望能帮助到你。


推荐阅读