Bug 1274924 - GeckoDriver.getTextFromDialog() throws "TypeError: can't convert null to object" r=AutomatedTester
MozReview-Commit-ID: G5p7gKjMYr7
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2470,81 +2470,76 @@ GeckoDriver.prototype.maximizeWindow = f
win.maximize()
};
/**
* Dismisses a currently displayed tab modal, or returns no such alert if
* no modal is displayed.
*/
GeckoDriver.prototype.dismissDialog = function(cmd, resp) {
- if (!this.dialog) {
- throw new NoAlertOpenError(
- "No tab modal was open when attempting to dismiss the dialog");
- }
+ this._checkIfAlertIsPresent();
let {button0, button1} = this.dialog.ui;
(button1 ? button1 : button0).click();
this.dialog = null;
};
/**
* Accepts a currently displayed tab modal, or returns no such alert if
* no modal is displayed.
*/
GeckoDriver.prototype.acceptDialog = function(cmd, resp) {
- if (!this.dialog) {
- throw new NoAlertOpenError(
- "No tab modal was open when attempting to accept the dialog");
- }
+ this._checkIfAlertIsPresent();
let {button0} = this.dialog.ui;
button0.click();
this.dialog = null;
};
/**
* Returns the message shown in a currently displayed modal, or returns a no such
* alert error if no modal is currently displayed.
*/
GeckoDriver.prototype.getTextFromDialog = function(cmd, resp) {
- if (!this.dialog) {
- throw new NoAlertOpenError(
- "No tab modal was open when attempting to get the dialog text");
- }
+ this._checkIfAlertIsPresent();
let {infoBody} = this.dialog.ui;
resp.body.value = infoBody.textContent;
};
/**
* Sends keys to the input field of a currently displayed modal, or
* returns a no such alert error if no modal is currently displayed. If
* a tab modal is currently displayed but has no means for text input,
* an element not visible error is returned.
*/
GeckoDriver.prototype.sendKeysToDialog = function(cmd, resp) {
- if (!this.dialog) {
- throw new NoAlertOpenError(
- "No tab modal was open when attempting to send keys to a dialog");
- }
+ this._checkIfAlertIsPresent();
// see toolkit/components/prompts/content/commonDialog.js
let {loginContainer, loginTextbox} = this.dialog.ui;
if (loginContainer.hidden) {
throw new ElementNotVisibleError("This prompt does not accept text input");
}
let win = this.dialog.window ? this.dialog.window : this.getCurrentWindow();
event.sendKeysToElement(
cmd.parameters.value,
loginTextbox,
{ignoreVisibility: true},
win);
};
+GeckoDriver.prototype._checkIfAlertIsPresent = function() {
+ if (!this.dialog || !this.dialog.ui) {
+ throw new NoAlertOpenError(
+ "No tab modal was open when attempting to get the dialog text");
+ }
+};
+
/**
* Quits Firefox with the provided flags and tears down the current
* session.
*/
GeckoDriver.prototype.quitApplication = function(cmd, resp) {
if (this.appName != "Firefox") {
throw new WebDriverError("In app initiated quit only supported in Firefox");
}