WebdriverIO and Protractor are built on the concept of promises:
Both WebdriverIO (and as a result, Protractor) APIs operate asynchronously. All functions return promises. WebdriverIO maintains a queue of pending promises known as the control flow to ensure organized execution.
Referencing the definition:
A promise is an object that represents a value or the future computation of a value. Initially, every promise is in a pending state and can either be successfully resolved with a value or be rejected to signal an error.
The aspect regarding promise rejection is something that I haven't fully grasped yet and have not encountered in Protractor. Typically, we utilize the pattern of using then()
and supplying a function for handling a successfully resolved promise:
element(by.css("#myid")).getAttribute("value").then(function (value) {
// manipulate the value here
});
The Query:
Is there a possibility that a promise returned by any of the Protractor/WebDriverJS functions may not be successfully resolved and could potentially be rejected? Is it necessary to consider this scenario and address it?