1

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>
kenorb
  • 155,785
  • 88
  • 678
  • 743
Martin Spa
  • 1,494
  • 1
  • 24
  • 44

1 Answers1

3

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)

Martin Spa
  • 1,494
  • 1
  • 24
  • 44
  • 1
    You probably can use the npm installed PhantomJS exe. What happened was probably that Java couldn't deal with the script that actually starts the exe. – Artjom B. Feb 17 '15 at 15:41
  • Correct, I can use the one from npm in console, but not from the JUnit test. Probably doesn't expect a .cmd but an .exe. – Martin Spa Feb 17 '15 at 15:45
  • @MartinSpa, where is the code repository for that artifact? com.codeborne:phantomjsdriver:1.2.1 – KoichiSenada Jul 02 '15 at 12:04
  • Hi! You can find it in Maven Central http://search.maven.org/#artifactdetails%7Ccom.codeborne%7Cphantomjsdriver%7C1.2.1%7Cjar – Martin Spa Jul 02 '15 at 14:21
  • 1
    @MartinSpa yeah, but where is the code repository for that artifact? Whether has it been forked from the original repository? https://repo1.maven.org/maven2/com/codeborne/phantomjsdriver/1.2.1/phantomjsdriver-1.2.1.pom - it states that the code base is still at https://github.com/detro/ghostdriver But what is the actual one and what are the changes? – KoichiSenada Jul 07 '15 at 04:58
  • Honestly I haven't checked the actual changes. You can get the source from phantomjsdriver-1.2.1-sources.jar and check it out; or you can ask the author (Andrei) here: https://code.google.com/p/selenium/issues/detail?id=8088 – Martin Spa Jul 07 '15 at 09:18