2016-04-13 163 views
4

我刚刚为Selenium WebDriver(a.k.a。Selenium 2)自动测试无头测试创建了一个简单的Maven项目。我加入了PhantomJS驱动程序与依赖pom.xml中的其他依赖如下:如何解决NoClassDefFoundError:CircularOutputStream错误?

<dependency> 
    <groupId>com.github.detro</groupId> 
    <artifactId>phantomjsdriver</artifactId> 
    <version>1.2.0</version> 
</dependency> 

但越来越错误:

java.lang.NoClassDefFoundError: org/openqa/selenium/io/CircularOutputStream 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60) 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56) 
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120) 
at jp.co.skygate.home.HomePageLogin.setUp(HomePageLogin.java:108) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at 

只删除从pom.xml中PhantomJS依赖性解决了这个问题,并它执行得很好。 有人可以帮我找到问题吗?

在此先感谢。

回答

4

最后我得到了解决方案。

添加PhantomJS v.1.2.0用selenium-remote-driver-2.41.0.jar替换了selenium-remote-driver-2.53.0.jar,因此打破了一切。 而现在使用V.2.41.0,而不是

driver = new FirefoxDriver(); 

driver = new PhantomJSDriver(caps); 

生成错误。

+2

所以,这是版本兼容性问题。你可以在selenium-remote-driver-2.53.0中使用phantomjsdriver 1.3.0 –

0

根据@Ripon comment,问题在于版本兼容性,所以Selenium Server 2.53.x应该与Phantom JS 1.3.x一起使用。

这里是在pom.xml线,应该工作:

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.53.1</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>com.codeborne</groupId> 
    <artifactId>phantomjsdriver</artifactId> 
    <version>1.3.0</version> 
</dependency> 

然后运行mvn dependency:tree建立并显示依赖关系树为这个项目。

如果你不使用Maven,你需要make sure you've all dependent jar files in your classpath