在摸索了几个小时之后,我们发现了以下解决方案 很难想象这应该是理想的方式。现在我想知道,量角器的预期方式应该是什么样的。
checkForToastMessage(expectedMessageText: string) {
browser.wait(function () {
browser.ignoreSynchronization = true;
return element(by.cssContainingText('.message-title', expectedMessageText)).isPresent()
.then(function(isPresent) {
if (!isPresent) {
$(".message-title").getText().then(function (text) {
console.log("found: " + text)
})
}
browser.ignoreSynchronization = false;
return isPresent;
});
}, 2000, "There was no Toast with the message '" + expectedMessageText + "' to display!");
}
checkForNoToastMessage() {
var timeout = 2000;
var start = 0;
while (start <= timeout) {
browser.sleep(100);
start += 100;
browser.wait(function () {
browser.ignoreSynchronization = true;
return element(by.css('.message-title')).isPresent()
.then(function(isPresent) {
browser.ignoreSynchronization = false;
expect(isPresent).toBeFalsy("no toaster was expected");
return true;
});
}, 100);
}
}
答案 0 :(得分:0)
借助 protracot.ExpectedConditions.visibilityOf() 方法,我们可以轻松地在量角器中的UI上找到烤面包机弹出窗口。它完美地运作。我们不需要这么冗长的逻辑。
您可以按照以下工作示例进行操作:
var EC=protractor.ExpectedConditions;
var ToasterPopUP = element(by.css('.message-title'));
EC.visibilityOf(ToasterPopUP ).call().then(function(isPresent){
expect(isPresent).toBeFalsy("no toaster was expected");
});