Skip to content

Commit

Permalink
[js] Add support for the alert credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Mar 11, 2016
1 parent 9da7301 commit 0b9d599
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
The top-level `error` module will be removed in v3.0.
* Moved `until.Condition` and `until.WebElementCondition` to the webdriver
module to break a circular dependency.
* Added support for setting the username and password in basic auth pop-up
dialogs (currently IE only).
* FIXED: `io.findInPath()` will no longer match against directories that have
the same basename as the target file.
* FIXED: `phantomjs.Driver` now takes a third argument that defines the path to
Expand Down
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const COMMAND_MAP = new Map([
[cmd.Name.DISMISS_ALERT, post('/session/:sessionId/dismiss_alert')],
[cmd.Name.GET_ALERT_TEXT, get('/session/:sessionId/alert_text')],
[cmd.Name.SET_ALERT_TEXT, post('/session/:sessionId/alert_text')],
[cmd.Name.SET_ALERT_CREDENTIALS, post('/session/:sessionId/alert/credentials')],
[cmd.Name.GET_LOG, post('/session/:sessionId/log')],
[cmd.Name.GET_AVAILABLE_LOG_TYPES, get('/session/:sessionId/log/types')],
[cmd.Name.GET_SESSION_LOGS, post('/logs')],
Expand Down
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const Name = {
DISMISS_ALERT: 'dismissAlert',
GET_ALERT_TEXT: 'getAlertText',
SET_ALERT_TEXT: 'setAlertValue',
SET_ALERT_CREDENTIALS: 'setAlertCredentials',

EXECUTE_SQL: 'executeSQL',
GET_LOCATION: 'getLocation',
Expand Down
27 changes: 27 additions & 0 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,23 @@ class Alert {
return this.text_;
}

/**
* Sets the username and password in an alert prompting for credentials (such
* as a Basic HTTP Auth prompt). This method will implicitly
* {@linkplain #accept() submit} the dialog.
*
* @param {string} username The username to send.
* @param {string} password The password to send.
* @return {!promise.Promise<void>} A promise that will be resolved when this
* command has completed.
*/
authenticateAs(username, password) {
return this.driver_.schedule(
new command.Command(command.Name.SET_ALERT_CREDENTIALS),
'WebDriver.switchTo().alert()'
+ `.authenticateAs("${username}", "${password}")`);
}

/**
* Accepts this alert.
*
Expand Down Expand Up @@ -2347,6 +2364,16 @@ class AlertPromise extends Alert {
});
};

/**
* Defers action until the alert has been located.
* @override
*/
this.authenticateAs = function(username, password) {
return alert.then(function(alert) {
return alert.authenticateAs(username, password);
});
};

/**
* Defers action until the alert has been located.
* @override
Expand Down

0 comments on commit 0b9d599

Please sign in to comment.