Skip to content

Commit 9d438c2

Browse files
johnjbartonjuangj
authored andcommitted
Save the promise before dispatchEvent().
The execute() API is async, it returns a promise. The FirefoxDomExecutor is synchronous, it 'sends' the command with dispatchEvent() and receives the response in the onResponse_ handler. Since we null the pendingCommand_ in the onResponse_ handler, we must save the the promise needed by the API before calling dispatchEvent(). Signed-off-by: Jason Juang <[email protected]>
1 parent 7bea19f commit 9d438c2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

javascript/webdriver/firefoxdomexecutor.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ webdriver.FirefoxDomExecutor.prototype.execute = function(command) {
129129
event.initEvent(webdriver.FirefoxDomExecutor.EventType_.COMMAND,
130130
/*canBubble=*/true, /*cancelable=*/true);
131131

132+
// The API for execute() is async, we need to promise the result.
133+
// Running in the browser, the response will be synchronous with
134+
// the dispatchEvent() call. Since we want to clear the pendingCommand_,
135+
// save its promise for the API return.
136+
var pseudoAsync = this.pendingCommand_.deferred.promise;
137+
132138
this.docElement_.dispatchEvent(event);
133139

134-
return this.pendingCommand_.deferred.promise;
140+
return pseudoAsync;
135141
};
136142

137143

0 commit comments

Comments
 (0)