Tuesday 4 August 2015

Start and Stop Selenium Server Programatically in Selenium

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.

     protected RemoteControlConfiguration rc ;
     protected SeleniumServer seleniumServer ;

     public void startSeleniumServer() {    

        try {
          File logfile = new File("logs/seleniumServer.log");
          rc = new RemoteControlConfiguration();
          rc.setLogOutFile(logfile);
          seleniumServer = new SeleniumServer(rc);
          seleniumServer.start();      
      } catch (Exception e) {
          e.printStackTrace();
      }
      }

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

No comments:

Post a Comment