javajunitselenium-webdriverphantomjsghostdriver

Selenium test with PhantomJSDriver is hanging and not finishing


First, I start the local webapp.

Next, when I run the following test in Eclipse as a JUnit test (with -Dbrowser=phantomjs):

@Test
public void homepageShowsSearchBox() throws Exception {
    open("http://localhost:8080/app/");
    $(By.cssSelector("#someSelector")).should(exist);
}

The test never finishes. It's like it is hanging. (When I open the same URL in a browser the webapp is displayed)

This is the console output:

Feb 17, 2015 3:28:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Users\xx\AppData\Roaming\npm\phantomjs
Feb 17, 2015 3:28:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 14234
Feb 17, 2015 3:28:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=14234, --webdriver-logfile=D:\Test Projects\demoapp-source\web\phantomjsdriver.log]
Feb 17, 2015 3:28:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}

Also, there is no phantomjsdriver.log (the one mentioned in the log).

If useful, these are the dependencies:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.codeborne</groupId>
  <artifactId>selenide</artifactId>
  <version>2.16</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.github.detro</groupId>
  <artifactId>phantomjsdriver</artifactId>
  <version>1.2.0</version>
  <scope>test</scope>
</dependency>

Solution

  • Solved, just

    1) change the dependency (reference):

        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.2.1</version>
            <scope>test</scope>
        </dependency>
    

    2) Don't use the npm-installed PhantomJS, but download the one from the website and add it as a parameter (-Dphantomjs.binary.path="C:\bin\phantomjs-2.0.0-windows\bin\phantomjs.exe") (reference)