2016-04-13 185 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