简体   繁体   中英

How to open another URL after executing base URL by using Selenium RC with Java

I have following methods of my class 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");
......
........
     }

After execution of Google site, I want to switch yahoo site from Google. I have written the following code of snippet:

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

I found the following errors:

com.thoughtworks.selenium.SeleniumException: Cannot call method 'indexOf' of undefined at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:100) at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:94) at 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) 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.Invok eMethod.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) 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.jav a: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)

How can I open another site rather than Base URL? Please help me

Ripon

It seems you need to close previous selenium session or reuse selenium instance:

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");
}

尝试 *chrome 而不是 *firefox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM