如何在使用Selenium RC和Java执行基本URL后打开另一个URL

时间:2011-12-28 09:59:19

标签: java selenium junit selenium-rc

我有类Test的以下方法:( Selenium RC,JUnit,Java,Eclipse)

@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:无法调用未定义的方法'indexOf'       在com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:100)       在com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:94)       在com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:343)        at abc.Test.testYahoo(Test.java:47)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)       at 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)       在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)       在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)       在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)       在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)       在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)       在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.ParentRunner $ 3.run(ParentRunner.java:231)       在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:60)       在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)       在org.junit.runners.ParentRunner.run(ParentRunner.java:300)       在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)       在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)       在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)

如何打开其他网站而不是基本网址?请帮帮我

里彭

2 个答案:

答案 0 :(得分:1)

您似乎需要关闭以前的selenium会话或重用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 :(得分:1)

尝试* chrome而不是* firefox