Enabling WebDriverJS to execute custom command "executePhantomScript" for PhantomJS

1,004 views
Skip to first unread message

Lukas Brückner

unread,
Aug 13, 2014, 6:07:15 AM8/13/14
to selenium-...@googlegroups.com
Hi,

the GhostDriver implementation for PhantomJS includes a custom command to execute phantom code. The related ticket can be found here https://github.com/detro/ghostdriver/pull/262.
This is for example necessary to handle alerts or confirms, since PhantomJS is not WebDriver compatible for them. (See https://github.com/detro/ghostdriver/issues/20 for more detail)
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:

  1. Is there actually a way to inject this functionality directly without changing the library?
  2. If not, would you consider the ability to extend the Executor to accomodate such functionality?
Thanks alot,
Lukas

Lukas Brückner

unread,
Nov 26, 2014, 4:28:03 AM11/26/14
to selenium-...@googlegroups.com
Sorry to bother again.

Do you think it would be possible to enable custom webdriver functions like the phantom-script feature?

Jason Leyba

unread,
Nov 26, 2014, 1:16:15 PM11/26/14
to selenium-...@googlegroups.com
Filed https://code.google.com/p/selenium/issues/detail?id=8221

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/b8211a53-0c67-4532-92b2-aaaf3898dad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages