Monday, December 20, 2010

Code to start and stop Selenium server with eclipse setup

This is the minimum code to start the server and shutdown.


package file;

import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.SeleniumServer;

public class Reset extends SeleneseTestCase {

private SeleniumServer seleniumServer;
private Selenium selenium = new DefaultSelenium( "localhost",4444,
"*chrome","http://");

public void setUp() throws Exception
{
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}


//Test methods shd go here

public void tearDown()throws Exception
{
selenium.stop();
seleniumServer.stop();
}

}
Eclipse Configuration

create new project->enter project name->next->libraries->add selenium server.jar and junit-4.8.2.jar and click finish.

Way to export the java program to eclipse IDE.

1)After recording test case,click on options->format->Junit 3
2)Copy the method and paste it in between setup and teardown method.
3)Run->run as Junit

You can see your test case running...Enjoy!!!

3 comments:

  1. What about using TestNG?
    How is this code could became in TestNG?

    ReplyDelete
  2. please check my other post containing the code for testNG

    ReplyDelete
  3. Hi,
    If i have 30 testcases, How can i run server only onces and stop after all testcases passes?

    Thanks
    Azhar

    ReplyDelete