用PhantomJSDriver进行的Selenium测试是挂起而没有完成

时间:2015-02-17 14:39:18

标签: java junit selenium-webdriver phantomjs ghostdriver

首先,我启动本地webapp。

接下来,当我在Eclipse中作为JUnit测试运行以下测试时(使用-Dbrowser=phantomjs):

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

测试永远不会结束。它就像悬挂一样。 (当我在浏览器中打开相同的URL时,会显示webapp)

这是控制台输出:

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: {}

此外,没有phantomjsdriver.log(日志中提到的那个)。

如果有用,这些是依赖项:

<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>

1 个答案:

答案 0 :(得分:3)

解决了,只是

1)更改依赖关系(reference):

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

2)不要使用npm安装的PhantomJS,而是从网站下载并将其作为参数添加(-Dphantomjs.binary.path="C:\bin\phantomjs-2.0.0-windows\bin\phantomjs.exe")(reference