After struggling for hours, we finally stumbled upon this solution. It's hard to believe that this is the optimal approach. Now, I'm curious to learn about the recommended method by the experts.
findToastMessage(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, "No Toast message with '" + expectedMessageText + "' was found!");
}
findNoToastMessage() {
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("Expected no toaster message");
return true;
});
}, 100);
}
}