javascript-如何在Angular的ProtractorJS中将.isDisplayed()与.each()一起使用
作者:互联网
我正在Angular应用程序中设置一个测试,以进入并单击一个元素,它应该查看是否显示了某个对象.尽管我知道isDisplayed()是针对单个元素而不是多个元素的,但我认为这里的代码应该可以工作.我知道有一个.each()函数,但不确定它是否适合此函数.如何将.each()与isDisplayed()结合使用?
it('should flip cards and check to make sure graph is visible', function(){
var cards = element.all(by.repeater('card in cards'));
var backOfCard = element.all(by.css('#current-status ul li .back canvas'));
expect(browser.getCurrentUrl()).toEqual('http://localhost:8000/app/#/dashboard');
expect(cards.count()).toBe(4);
cards.click().then(function(){
expect(backOfCard.isDisplayed()).toBe([true, true, true, true]);
});
});
解决方法:
您实际上可以在ElementArrayFinder上调用isDisplayed():
expect(backOfCard.isDisplayed()).toBe([true, true, true, true]);
或者,可以在这里使用map()
:
var values = backOfCard.map(function (elm) {
return elm.isDisplayed();
});
expect(values).toBe([true, true, true, true]);
而且,您甚至可以reduce()
来检查单个布尔值:
var allDisplayed = backOfCard.reduce(function (acc, elm) {
return elm.isDisplayed().then(function (isDisplayed) {
return isDisplayed && acc;
});
}, false);
expect(allDisplayed).toBeTrue();
标签:angularjs,selenium,testing,protractor,javascript 来源: https://codeday.me/bug/20191119/2037296.html