【问题标题】:Junit test with WebDriver fails an ant run使用 WebDriver 的 Junit 测试无法通过 ant 运行
【发布时间】:2014-08-03 20:42:25
【问题描述】:

我正在运行一个 junit 测试,它使用 WebDriver 打开一个谷歌页面(它在一个包 testing.com 中,文件名为 GoogleTest。它在 eclipse 中通过,当我在命令中给出命令“mvn test”时它通过了。但是,当我使用命令行运行 ant 构建并触发“ant run”命令时,我得到以下输出 - [junit] 测试运行:1,失败:0,错误:1,跳过:0, 报错为:

Error   INSTANCE

java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:68)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:54)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:93)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at testing.com.GoogleTest.testGoogle(GoogleTest.java:20)
    10.578

非常感谢您的意见,因为我尝试了很多方法,但仍然遇到同样的错误。

我的 java jdk 路径很好 - 已经检查了几次,我将所有 SELENIUM jar 文件添加到 CLASSPATH 中,包括另一篇文章所建议的 Selenium SERVER 独立 jar 文件。

任何帮助将不胜感激。

【问题讨论】:

  • 试试mvn clean test。另外,在同一个项目中混合使用 Ant 和 Maven 有什么好处?

标签: maven selenium ant junit selenium-webdriver


【解决方案1】:

您使用的是哪个版本的 Java、Selenium 和 ant?

这似乎是版本不匹配或版本兼容性问题。我建议您检查您的类路径中是否有两个不同版本的 Selenium,如果是,则将其设为一个。同样,您应该确保您的系统上仅设置了单一且兼容的 ant 版本

试一试,让我知道。

【讨论】:

  • 感谢您的及时回复-我使用的是 1.9.2 版本的 apache ant、java jdkl1.7.0_60 和 Selenium 2.42.2。我检查了类路径,并向其中添加了最新版本的 Selenium Client jars 和 StandAlone 服务器 jars-通过命令行添加了类路径-我只能找到一个版本的 ant 和
  • 问题得到了解决——我在我的机器 c:\junit 上安装了 junit,并在环境变量中将 junit_home 设置为 c:\juniT。 (我使用的是 WINDOWS 7)。我更改了我的 build.xml 文件 - 使用了来自 Web 的 build.xml,其中包括对 Selenium Standalone Server 的引用 -eg" " 在我自己的 build.xml 中,我通过 maven 存储库引用 Selenium jar-.M2\REPOSITORY
猜你喜欢
  • 1970-01-01
  • 2011-05-29
  • 2012-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-29
相关资源
最近更新 更多