Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support phantomjs-prebuilt in selenium-webdriver #2069

Closed
huan opened this issue May 9, 2016 · 11 comments
Closed

Feature request: support phantomjs-prebuilt in selenium-webdriver #2069

huan opened this issue May 9, 2016 · 11 comments

Comments

@huan
Copy link

huan commented May 9, 2016

Meta -

OS: Win32

Selenium Version: 2.53.2

Browser: phantomjs, which installed by npm install phantomjs-prebuilt

Browser Version: 2.1.7

Expected Behavior -

npm install selenium-webdriver
npm install phantomjs-prebuilt

node js source

const driver = new WebDriver.Builder()
.withCapabilities(
  WebDriver.Capabilities.phantomjs()
).build()

should find phantomjs executable, and return success.

Actual Behavior -

cant find phantomjs executable.

test\node_modules\selenium-webdriver\phantomjs.js:80
    throw Error(
    ^

Error: The PhantomJS executable could not be found on the current PATH. Please download the latest version from http://phantomjs.org/download.html and ensure it can be found on your PATH. For more information, see https://github.com/ariya/phantomjs/wiki
    at Error (native)
    ...

Steps to reproduce -

step 1. open cmd window
step 2. run

mkdir test
cd test
npm install selenium-webdriver
npm install phantomjs-prebuilt

step 3. then run this node js source

const WebDriver = require('selenium-webdriver')
const driver = new WebDriver.Builder()
.withCapabilities(
  WebDriver.Capabilities.phantomjs()
).build()

step 4. webdriver said that cant find phantomjs executable.

Steps to quick fix -

step 1. find executable installed by phatomjs-prebuilt in node_modules.bin

  D:\test>dir node_modules\.bin\phantomjs*
   node_modules\.bin 的目录

  2016/05/09  11:59               335 phantomjs
  2016/05/09  11:59               212 phantomjs.cmd

step 2. reason: in selenium-webdriver/phantomjs.js:

  const PHANTOMJS_EXE =
      process.platform === 'win32' ? 'phantomjs.exe' : 'phantomjs';

it only find .exe . but the phantomjs-prebuilt installed executable name is .cmd
step 3. fix: add .cmd to search io.findPath:

function findExecutable(opt_exe) {
  const PHANTOMJS_CMD = 'phantomjs.cmd'
  var exe = opt_exe || io.findInPath(PHANTOMJS_EXE, true) || io.findInPath(PHANTOMJS_CMD, true);
@jleyba
Copy link
Contributor

jleyba commented May 9, 2016

Marking this as a feature request as we've never claimed to support phantomjs-prebuilt. I will not accept a PR that introduces a dependency on that module, but would consider a PR that made selenium-webdriver aware of it when searching for the executable.

@jleyba jleyba changed the title javascript phantomjs webdriver not compatible with npm install phantomjs-prebuilt Feature request: support phantomjs-prebuilt in selenium-webdriver May 9, 2016
@huan
Copy link
Author

huan commented May 9, 2016

thanks. please support search .cmd file, because when we use npm in win32, almost all executable installed in node_modules/.bin is named with a ".CMD" ext.

@vtange
Copy link
Contributor

vtange commented May 11, 2016

Happened to be working with this issue and found that you can technically get around this by building a PhantomJS driver around a custom Capability linking to the location of the executable.

You just write something like this in the beginning of your own test, no need to modify selenium's code:

//setup custom phantomJS capability
const phantomjs_exe = require('phantomjs-prebuilt').path;
var customPhantom = selenium.Capabilities.phantomjs();
customPhantom.set("phantomjs.binary.path", phantomjs_exe);

//build custom phantomJS driver
const driver = new selenium.Builder().
       withCapabilities(customPhantom).
       build();

Since Selenium provides instructions for how to work with a custom Firefox install, I wrote instructions for how to use phantomjs-prebuilt with selenium-webdriver here

@huan
Copy link
Author

huan commented May 12, 2016

@vtange ah, this is good. because at last I need not to hard code the PATH in my code.

thanks!

@mekdev
Copy link

mekdev commented Oct 10, 2016

Seconded @jleyba on not putting dependency on phantom-js-prebuilt.

That project has a known problematic install with CDN flakkiness, there is a myriad of issues filed against this.

See:

And Medium/phantomjs#598 (comment)
Where we explain the root cause. We have removed this dependency from our CI pipeline completely.

There are also other alternative to configure phantomjs support out of the box.
E.g. with a library like selenium-standalone maintained by the folks at Saucelabs.
See - https://www.npmjs.com/package/selenium-standalone
You will have to configure the way you build your driver to use this library and just specify phantomjs as the configuration parameter.

new webdriver.Builder().usingServer(`http://${selenium.hostname}:${selenium.port}/wd/hub`);

with the following parameters

selenium: {
   hostname: 'localhost',
    port: '4444'
}

Also with headless chrome coming out soon, it might be worth it to transition to use Chrome all together

@deanmarano
Copy link

With the phantomjs npm package being deprecated and phantomjs-prebuilt becoming the recommendation, is there any change in support expected?

@manoj9788
Copy link
Member

with chrome headless now being available - Should this still be an option?

@huan
Copy link
Author

huan commented Aug 17, 2017

@manoj9788 I just start to use chrome headless today.

    const options = {
        args: [
        '--disable-gpu',
        '--headless', // https://developers.google.com/web/updates/2017/04/headless-chrome
        '--homepage=about:blank',
        '--no-sandbox',
      ],  // issue #26 for run inside docker

See:

  1. wechaty/wechaty@4e3601f
  2. chrome-headless support wechaty/wechaty#739

@manoj9788
Copy link
Member

Nice, so can you close this issue?

@huan huan closed this as completed Aug 17, 2017
@manoj9788
Copy link
Member

Thanks

@huan
Copy link
Author

huan commented Aug 17, 2017

You are welcome. :)

@lock lock bot locked and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants