2012-07-19 42 views
0

我只是想執行基本的硒測試。沒什麼特別的,只是爲了確保它的工作。 但是引發異常。 我能做什麼錯? java -jar selenium-server-standalone-2.24.1.jarSelenium WebDriver的簡單測試設置失敗

import static org.junit.Assert.fail; 

import java.util.concurrent.TimeUnit; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.NoSuchElementException; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class Selenium { 
    private WebDriver driver; 
    private String baseUrl; 
    private StringBuffer verificationErrors = new StringBuffer(); 

    @Before 
    public void setUp() throws Exception { 
     driver = new FirefoxDriver(); 
     baseUrl = "http://www.google.de/"; 
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
    } 

    @Test 
    public void testSeleniumWeb() throws Exception { 
    //empty just for testing 
    } 
} 

拋出:

當然我開始使用服務器

java.lang.AbstractMethodError: org.apache.crimson.tree.ElementNode2.getTextContent()Ljava/lang/String; 
    at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:134) 
    at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61) 
    at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64) 
    at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:547) 
    at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:525) 
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74) 
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149) 
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:78) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:79) 
    at de.coconet.soapui.selenium.setUp(selenium.java:15) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
+0

它看起來像是在尋找一個不支持getTextContent()方法的舊XML解析器(Apache Crimson)。 – 2012-07-19 09:25:29

回答

3

它無關,與你的代碼。你有一個類路徑問題。有些類依賴於ElementNode2的不同版本,而不是類路徑中第一個找到的版本。

如果你看看jarfinder,你可以看到在JDK 1.4之後,這個類包含在Java運行時(rt.jar)中。

我懷疑你使用的JDK版本比WebDriver針對的版本要舊。 WebDriver需要JDK 1.6+。