Just like falling in love with promises only after the arrival of async/await
, my journey with this concept has been a puzzle.
/**
* WebElementPromise is a promise that will be fulfilled with a WebElement.
* This serves as a forward proxy on WebElement, allowing calls to be
* scheduled without directly on this instance before the underlying
* WebElement has been fulfilled. In other words, the following two statements
* are equivalent:
*
* driver.findElement({id: 'my-button'}).click();
* driver.findElement({id: 'my-button'}).then(function(el) {
* return el.click();
* });
The presence of then()
in the second statement makes logical sense - the promise resolves with the element, and then executes then()
.
However, I find myself pondering over what’s happening when we have
driver.findElement({id: 'my-button'}).click();
. The call to driver.findElement({id: 'my-button'})
results in an unfilled promise. As far as I know, a promise can only have then()
and catch()
. So, what exactly is the role of click()
here?
Moreover, the explanation mentioning a “forward proxy” leaves me bewildered and lost in understanding.