关闭

SeleniumGrid配置

280人阅读 评论(0) 收藏 举报

1 HUB的配置

确认HUB终端有JRE环境

java -version
可以看到以下信息即为成功

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)


下载selenium-server-standalone,下载地址点我

启动命令(jar包请自行替换为下载的jar包文件名,路径自行指定)

java -jar seleniumServer的jar包 -role hub
启动成功后可见以下信息(采用默认方式启动,hub端口号为4444)

07:19:26.387 INFO - Launching Selenium Grid hub
2016-05-31 07:19:27.487:INFO::main: Logging initialized @1361ms
07:19:27.501 INFO - Will listen on 4444
07:19:27.607 INFO - Will listen on 4444
2016-05-31 07:19:27.619:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT
2016-05-31 07:19:27.681:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@7403c468{/,null,AVAILABLE}
2016-05-31 07:19:27.735:INFO:osjs.ServerConnector:main: Started ServerConnector@401e7803{HTTP/1.1}{0.0.0.0:4444}
2016-05-31 07:19:27.735:INFO:osjs.Server:main: Started @1609ms
07:19:27.736 INFO - Nodes should register to http://192.168.0.16:4444/grid/register/
07:19:27.737 INFO - Selenium Grid hub is up and running


2 Node的配置

本例node环境为OpenSUSE

启动命令(server的jar包请自行替换为下载的jar包文件名,defaultNodeConfig.json为hub配置文件,路径自行指定)

 java -jar server的jar包 -role node -nodeConfig defaultNodeConfig.json

HUB配置文件例(以windows为例)

红字部分请根据hub终端的ip和port自行修改,driver路径请根据node终端自行配置

蓝色部分为HUB的执行能力,本配置文件指定为window,浏览器有firefox,chrome和ie

{
  "capabilities":
      [
       {
          "browserName": "firefox",
          "platform": "WINDOWS",
          "maxInstances": 2
        },
        {
          "browserName": "chrome",
          "platform": "WINDOWS",
          "maxInstances": 1
        },
        {
          "browserName": "internet explorer",
          "platform": "WINDOWS",
          "maxInstances": 1
        }
      ],
  "configuration":
  {
    "maxSession": 3,
    "port": 5555,
    "timeout":30000,
    "register": true,
    "registerCycle": 10000,
    "hubPort":hub port,
    "hubHost": hub ip,
    "Dwebdriver.ie.driver=C:/my/IEDriverServer_Win32_2.48.0/IEDriverServer.exe": ""
  }
}

启动成功后hub端的log可见

15:20:14.653 INFO - Registered a node http://9.197.70.93:5555

Node端最后可见

15:20:14.613 INFO - Registering the node to the hub: http://localhost:4444/grid/register
15:20:14.653 INFO - The node is registered to the hub and ready to use


3 执行测试

        //指定测试环境为firefox
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        //指定平台为LINUX
        dc.setPlatform(Platform.LINUX);</span>
        WebDriver driver = new RemoteWebDriver(new URL("http://hubip:4444/wd/hub"), dc);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("http://www.baidu.com");
hubip请自行替换

执行该段代码,hub会在已经注册的node中匹配相应的环境,并分发任务执行。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4512次
    • 积分:104
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章存档