selenium RC-更改默认端口4444端口。如果端口在运行时忙

时间:2011-05-23 16:00:09

标签: selenium selenium-rc

如何在运行SELENIUM RC时处理该场景。如果我们得到默认端口4444正忙。

1 个答案:

答案 0 :(得分:2)

首先需要检查端口4444是否正忙。如果它正忙,则将RC设置为使用其他端口。

   static int port=4444;
          try {
             ServerSocket serverSocket = new ServerSocket(port);
             //Checking whether 4444 is closed or not
             if(!serverSocket.isClosed())
                port=5555;//Or whatever port you like
             //Now start selenium server
             RemoteControlConfiguration rcc = new RemoteControlConfiguration();
             rcc.setPort(port);
             SeleniumServer server = new SeleniumServer(false, rcc);
             server.start();  }

          catch(Exception e){
            e.printStackTrace(); }