I am newbie with protractor (and async javascript) but my last few weeks of learning I really like it.
Since we deal with objects, I was trying to come up with a function which returns boolean value if the object is visible/exist.
A partial implementation would like this:
function waitObject(elm, timeout) {
return browser.driver.wait(function() {
return elm.isPresent().then(function(res) {
return res;
});
}, timeout);
}
I'd like to achieve 2 things here:
1) It return true/false after the timeout.
2) When it's false, it doesn't throw the timeout error but just false. So, I can continue with my remaining test.
Just use
then
asbrowser.wait
returns a promise which resolves or rejects depending on the condition passed tobrowser.wait
: http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.waitThis way you can do different things depending on if the condition timed out or not.
I think it would be tricky though to not return a promise from the function. As everything done in Protractor happens async.