我从BitMotif - Selenium Remote Control For Java - A Tutorial得到了这段代码
package Practice;
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.DefaultSelenium;
import junit.framework.TestCase;
import org.openqa.selenium.server.SeleniumServer;
public class TestMangaPanda
extends TestCase
{
private static final String MAX_WAIT_TIME_IN_MS = "6000";
private static final String BASE_URL = "http://www.bitmotif.com";
private Selenium selenium = new DefaultSelenium( "localhost",
4444,
"*firefox",
BASE_URL);
SeleniumServer seleniumServer;
public void setUp() throws Exception
{
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}
public void tearDown()
throws Exception
{
selenium.stop();
seleniumServer.stop();
}
public void testClickingLink()
throws Exception
{
selenium.open(BASE_URL);
selenium.click("link=Test Page For Selenium Remote Control");
selenium.waitForPageToLoad(MAX_WAIT_TIME_IN_MS);
String expectedTitle = "Bit Motif » Test Page For Selenium Remote Control";
assertEquals(expectedTitle, selenium.getTitle());
}
}
这是使用 Selenium RC 进行的基本单元测试,但它继续得到这个例外:
java.lang.IllegalAccessError: 试图访问方法 org.openqa.selenium.browserlaunchers.LauncherUtils.getSeleniumResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream; 来自 org.openqa.selenium.server.SeleniumServer.logVersionNumber(SeleniumServer.java:265) 的 org.openqa.selenium.server.SeleniumServer.logStartupInfo(SeleniumServer.java:673) 的类 org.openqa.selenium.server.SeleniumServer org.openqa.selenium.server.SeleniumServer.(SeleniumServer.java:229) at org.openqa.selenium.server.SeleniumServer.(SeleniumServer.java:205) at Practice.TestMangaPanda.setUp(TestMangaPanda.java:21) at junit .framework.TestCase.runBare(TestCase.java:132) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult .
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在 org.eclipse。 jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
谢谢 :D