Hi,
GhostDriver includes an extended PhantomJSDriver to take advantage of that feature for Java.
For the WebDriverJS implementation, however, I did not find a good way to inject this command because the webdriver.http.Executor.COMMAND_MAP_ is private and execute will throw an error if it does not find a match between a requested command and a path in the command map.
That is why I had to fork the WebDriverJS package and inject the feature like so:
// lib/webdriver/http/http.js:176
webdriver.http.Executor.COMMAND_MAP_ = (function() {
return new Builder().
...
put(webdriver.CommandName.EXECUTE_PHANTOM_SCRIPT,
post('/session/:sessionId/phantom/execute')).
...
// lib/webdriver/command.js:101
webdriver.CommandName = {
...
EXECUTE_PHANTOM_SCRIPT: 'executePhantomScript',
...
};
// lib/webdriver/webdriver.js:505
// new command to run a PhantomJS script
// for the Java implementation
webdriver.WebDriver.prototype.executePhantomJS = function(script, var_args) {
if (goog.isFunction(script)) {
script = 'return (' + script + ').apply(this, arguments);';
}
return this.schedule(
new webdriver.Command(webdriver.CommandName.EXECUTE_PHANTOM_SCRIPT).
setParameter('script', script).
setParameter('args', goog.array.slice(arguments, 1)),
'WebDriver.executePhantomJS()');
};
This is working fine, but definitely not ideal, since I have to keep it up-to-date with your updates in the future.
So my question is:
- Is there actually a way to inject this functionality directly without changing the library?
- If not, would you consider the ability to extend the Executor to accomodate such functionality?
Thanks alot,
Lukas