Tuesday, December 06, 2011

Start and Stop Selenium Server Programatically

The Following code contains two methods.The first method startSeleniumServer() is for starting the server and the second method stopSeleniumServer() is to stop the started server.With this we are also able to trace out the server log to a file called "logs/seleniumServer.log" into your local machine. 
  1.  protected RemoteControlConfiguration rc ;
  2.  protected SeleniumServer seleniumServer ;
  3.  
  4.  public void startSeleniumServer() {      
  5.     try {
  6.       File logfile = new File("logs/seleniumServer.log");
  7.       rc = new RemoteControlConfiguration();  
  8.       rc.setLogOutFile(logfile);  
  9.       seleniumServer = new SeleniumServer(rc);
  10.       seleniumServer.start();        
  11.   } catch (Exception e) {
  12.       e.printStackTrace();
  13.   }
  14.   }
  15.  
  16.   public void stopSeleniumServer() throws Exception {
  17.      seleniumServer.stop();
  18.   } 

No comments:

Post a Comment