Skip to content

Commit

Permalink
Support the execute/sync endpoint
Browse files Browse the repository at this point in the history
fixes #143
  • Loading branch information
John Dorlus authored and jason0x43 committed Jul 17, 2018
1 parent b55b8d6 commit cfa51fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ Server.prototype = {
capabilities.browserVersion = capabilities.version;
}

// WebDriver Spec now supports execute/sync as the synchronous
// execute endpoint. This was updated in geckodriver as of 16.0
// but not yet completed in chromedriver.
capabilities.useExecuteSyncEndpoint = false;

// WebDriver Spec now supports [POST] /value receiving a
// parameter named 'text' as a string instead of an array of
// charactrers named 'value'. This was updated in geckodriver as
Expand Down
13 changes: 11 additions & 2 deletions Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,19 @@ Session.prototype = {
throw new Error('Arguments passed to execute must be an array');
}

var result = this._post('execute', {
var self = this;
var route = this.capabilities.useExecuteSyncEndpoint ? 'execute/sync' : 'execute';
var result = this._post(route, {
script: util.toExecuteString(script),
args: args || []
}).then(lang.partial(convertToElements, this), fixExecuteError);
}).then(lang.partial(convertToElements, this), fixExecuteError).catch(function (error) {
if (error.detail.error === 'unknown command'
&& !self.capabilities.useExecuteSyncEndpoint) {
self.capabilities.useExecuteSyncEndpoint = true;
return self.execute(script, args);
}
throw error;
});

if (this.capabilities.brokenExecuteUndefinedReturn) {
result = result.then(function (value) {
Expand Down

0 comments on commit cfa51fb

Please sign in to comment.