2011-12-28 117 views
1

執行基本URL打開另一個URL我有以下我Test類的方法:(硒RC,JUnit中,Java的是,Eclipse)如何通過使用Selenium RC與Java

@Before 
public void setUp() throws Exception { 
    selenium = new DefaultSelenium("localhost", 4444, "*firefox","https://www.google.com/"); 
    selenium.start(); 
    } 
@Test 
public void testGoogle() throws Exception { 
    selenium.open("https://www.google.com"); 
...... 
........ 
    } 

谷歌網站的執行後,我想從Google切換雅虎網站。我已經寫片斷如下代碼:

@Test 
public void testYahoo() throws Exception { 
    selenium.open("http://www.yahoo.com/"); //error in this line 
........ 
........ 
    } 

我發現了以下錯誤:

com.thoughtworks.selenium.SeleniumException:不能調用方法在com.thoughtworks的不確定 '的indexOf'。 selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:100) 在com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:94) 在com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:343) 在abc.Test.testYahoo(Test.java:47) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在sun.reflect。 DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在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.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners。 ParentRunner.runLeaf(ParentRunner.java:263) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 的組織。 (org.junit.runners.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java: 229) 在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:50) 在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) 在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)

如何打開另一個網站而不是基本網址?請幫我

裏彭

回答

1

看來你需要關閉以前的硒會話或重用selenium例如:

private static Selenium selenium; 

@BeforeClass 
public static void beforeClass() throws Exception { 
    selenium = new DefaultSelenium("localhost", 4444, "*firefox","https://www.google.com/"); 
    selenium.start(); 
} 

@Test 
public void testGoogle() throws Exception { 
    selenium.open("https://www.google.com"); 
} 

@Test 
public void testYahoo() throws Exception { 
    selenium.open("https://www.yahoo.com"); 
} 
1

嘗試*鉻,而不是*火狐