2011-12-28 109 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

尝试*铬,而不是*火狐