setting PhantomJSDriverService.PHANTOMJS_GHOSTDRIV

2019-07-31 17:23发布

I have difficulties setting the capability PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY in my Java program correctly in order to use the newest version of Ghostdriver from github together with my installed phantomjs version (1.9.1)

Here is what I do in my Java program

DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(
    PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
    "/xxx/phantomjs-1.9.1-linux-x86_64/bin/phantomjs" );
caps.setCapability(
    PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,
    "/xxx/ghostdriver/src/main.js");
WebDriver driver = new PhantomJSDriver(caps);

The selenium driver starts correctly, if i do not set the PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, but I get some errors in my tests that are supposed to be fixed in the current developer branch of ghostdriver. So i followed this advice and set up the cuttent github version of ghostdriver.

However, now I get the following error:

[ERROR - 2013-07-12T10:22:36.897Z] GhostDriver - Main - Could not start Ghost Driver => {
  "message": "Could not start Ghost Driver",
  "line": 79,
  "sourceId": 140320571924032,
  "sourceURL": "/xxx/ghostdriver/src/main.js",
  "stack": "Error: Could not start Ghost Driver\n    at /xxx/ghostdriver/src/main.js:79",
  "stackArray": [
    {
      "sourceURL": "/xxx/ghostdriver/src/main.js",
      "line": 79
    }
  ]
}

My question is, does anyone know how to fix this? Must I change the config.js of ghostdriver somehow to make this work?

Info: I am crossposting this also to the github issues of ghostdriver.

4条回答
小情绪 Triste *
2楼-- · 2019-07-31 17:32

I fixed this problem by seeing if my port was being used with netstat -tulnap That shows you a list of all the ports in use. Find the one that phantomjs is using. Then you can kill the process using fuser <your-port-number>/tcp -k. For example, my port was 4444 so fuser 444/tcp -k

查看更多
Lonely孤独者°
3楼-- · 2019-07-31 17:38

Kill any phantomjs process that is running and try again:

ps aux | grep phantom
kill -9 <your phantom process id>

Then try running phantomjs again.

查看更多
Summer. ? 凉城
4楼-- · 2019-07-31 17:43

So I had the same problem, it was that the port I was attempting to use was already in use. Try a different port. i.e:

phantomjs --webdriver=8089 --webdriver-selenium-grid-hub=...

查看更多
你好瞎i
5楼-- · 2019-07-31 17:46

I turns out, that this only works as expected for selenium version >= 2.33. I updated my selenium and this fixed the issue.

查看更多
登录 后发表回答