checkGridData(name: string, searchObj: ElementArrayFinder) {
if (name != "") {
let counter = 0;
let beforesplit = name;
let aftersplit = beforesplit.split("|");
var countval = searchObj.count();
return searchObj.count().then((count) => {
for (let i = 0; i < aftersplit.length; i++) {
let countval = searchObj.count();
// expect(count).toBe(expectedRecords[i]);
for (let j = 0; j < count; j++) {
searchObj.get(j).getText().then(function (text) {
if (text.indexOf(aftersplit[i]) !== -1) {
expect(text).toContain(aftersplit[i]);
++counter
//console.log("counter inside loop is" + counter)
}
return counter;
});
}
}
});
}
}
我是新来的量角器。我在下面写了一个函数
我正在另一个函数中调用它。
var abc = this.CheckGridData(ProductData.AddEquipment.EquipmentSelection, ProductObj.ele_equipmentvalidation)
console.log("Counter value returned:" + abc)
我收到此错误
返回的计数器值:ManagedPromise :: 5760 {[[PromiseStatus]]:“待处理”}
我试图做承诺,但是我不知道如何解决承诺。如何解决上面的for循环内部问题,以便我可以使用它并了解概念?我尝试了各种站点,但不知道如何解决。
答案 0 :(得分:0)
由于函数CheckGridData
返回了一个保证,因此变量abc
是一个保证。
要消耗诺言的最终价值,您必须使用then()
,如下所示:
checkGridData(name: string, searchObj: ElementArrayFinder) {
if (name != "") {
let counter = 0;
let beforesplit = name;
let aftersplit = beforesplit.split("|");
return searchObj.getText().then((texts) => {
// texts is an string array of text of all elements of searchObj
for (let i = 0; i < aftersplit.length; i++) {
if(texts.includes(aftersplit[i])) {
++counter;
}
}
return counter;
};
}
}
var abc = this.CheckGridData(ProductData.AddEquipment.EquipmentSelection,
ProductObj.ele_equipmentvalidation)
abc.then(function(count){
console.log(count);
})