class AlertPromise
webdriver.Alert └ webdriver.AlertPromise
- All implemented interfaces
IThenable<T>
webdriver.promise.Thenable<webdriver.Alert>
AlertPromise is a promise that will be fulfilled with an Alert. This promise serves as a forward proxy on an Alert, allowing calls to be scheduled directly on this instance before the underlying Alert has been fulfilled. In other words, the following two statements are equivalent:
driver.switchTo().alert().dismiss();
driver.switchTo().alert().then(function(alert) {
return alert.dismiss();
});
new AlertPromise(driver, alert)
- driver
webdriver.WebDriver
The driver controlling the browser this alert is attached to.
- alert
webdriver.promise.Thenable<webdriver.Alert>
A thenable that will be fulfilled with the promised alert.
Instance Methods
accept()code »
Defers action until the alert has been located.
Overrides: webdriver.Alert
webdriver.promise.Promise<undefined>
A promise that will be resolved when this command has completed.
cancel(opt_reason)code »
Cancels the computation of this promise's value, rejecting the promise in the process. This method is a no-op if the promise has already been resolved.
Specified by: webdriver.promise.Thenable
- opt_reason
?(string|webdriver.promise.CancellationError)=
The reason this promise is being cancelled.
dismiss()code »
Defers action until the alert has been located.
Overrides: webdriver.Alert
webdriver.promise.Promise<undefined>
A promise that will be resolved when this command has completed.
getText()code »
Defer returning text until the promised alert has been resolved.
Overrides: webdriver.Alert
webdriver.promise.Promise<string>
A promise that will be resolved to the text displayed with this alert.
isPending()code »
Specified by: webdriver.promise.Thenable
boolean
Whether this promise's value is still being computed.
sendKeys(text)code »
Defers action until the alert has been located.
Overrides: webdriver.Alert
- text
string
The text to set.
webdriver.promise.Promise<undefined>
A promise that will be resolved when this command has completed.
then(opt_callback, opt_errback)code »
Registers listeners for when this instance is resolved.
Specified by: webdriver.promise.Thenable, IThenable
- opt_callback
?function(T): (R|IThenable<R>)=
The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.
- opt_errback
?function(*): (R|IThenable<R>)=
The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.
webdriver.promise.Promise
A new promise which will be resolved with the result of the invoked callback.
thenCatch(errback)code »
Registers a listener for when this promise is rejected. This is synonymous
with the catch
clause in a synchronous API:
// Synchronous API:
try {
doSynchronousWork();
} catch (ex) {
console.error(ex);
}
// Asynchronous promise API:
doAsynchronousWork().thenCatch(function(ex) {
console.error(ex);
});
Specified by: webdriver.promise.Thenable
- errback
function(*): (R|IThenable<R>)
The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.
webdriver.promise.Promise
A new promise which will be resolved with the result of the invoked callback.
thenFinally(callback)code »
Registers a listener to invoke when this promise is resolved, regardless
of whether the promise's value was successfully computed. This function
is synonymous with the finally
clause in a synchronous API:
// Synchronous API:
try {
doSynchronousWork();
} finally {
cleanUp();
}
// Asynchronous promise API:
doAsynchronousWork().thenFinally(cleanUp);
Note: similar to the finally
clause, if the registered
callback returns a rejected promise or throws an error, it will silently
replace the rejection error (if any) from this promise:
try {
throw Error('one');
} finally {
throw Error('two'); // Hides Error: one
}
promise.rejected(Error('one'))
.thenFinally(function() {
throw Error('two'); // Hides Error: one
});
Specified by: webdriver.promise.Thenable
- callback
function(): (R|IThenable<R>)
The function to call when this promise is resolved.
webdriver.promise.Promise
A promise that will be fulfilled with the callback result.