2017-10-04 64 views
0

我有一个"Unordered list view"在我需要自动化的Angular应用程序中,我想使用“量角器”脚本检索该列表视图的计数。如何使用“量角器”工具将“Promise <Number>”类型转换为“Integer”类型

我使用下面的代码

var length = element.all(by.className('badge')).count(); 

现在我想用上面的“长度”变量“For循环”,如下图。

for(var i=0 ; i<length ; i++){} 

然后在“For循环”上面的“length”变量显示下面的错误信息。 不能应用于类型'数字'和Promise

那么谁能帮助我如何将"Promise <number>"变量转换为"integer"变量?

+1

可能重复的[量角器 - 比较数字](https://stackoverflow.com/questions/28076983/protractor-compare-numbers) – Nikolas

回答

0

count()返回承诺。现在你只需要解决你的承诺。这会为你工作

element.all(by.className('badge')).count().then(function(size){ 
    length = size; 
    console.log(size.toString()); //if you like to see it 

    //put the for loop code here within the then() as else your promise stays unresolved 
}); 

找到例子here或类似的情况下here更多地了解它。

+0

它的工作对我来说。感谢您的评论 – vasundhara

+0

很高兴,我可以帮忙。请将答案标记为正确答案,因为它对您有用。 –

相关问题