Selenium Grid学习笔记

安装jdk,selenium-server-standalone-xxx.jar,准备好各浏览器的驱动(主要是chromedriver和iedriver)

1.启动hub
java -jar selenium-server-standalone-2.53.0.jar -role hub

2.启动node
  2.1)单独模式,如果是访问别的主机的浏览器,需要将localhost替换为对应主机名
java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://localhost:4444/grid/register
  2.2)通过json启动
java -jar selenium-server-standalone-2.53.0.jar -role node -nodeConfig node-json-XXX.cfg.json

{
  "capabilities":
    [
      {
        "browserName": "firefox",
        "version": 43,
        "maxInstances": 5,
        "seleniumProtocol": "WebDriver"
        "platform": WINDOWS
      },
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": localhost,
    "register": true,
    "registerCycle": 5000,
    "htbPort": 4444,
    "hubHost": localhost
  }
}

  2.3)指定浏览器版本模式
java -jar selenium-server-standalone-2.53.0.jar -role node -browser "seleniumProtocol=WebDriver, browserName=chrome, version=61, maxInstances=5, platform = WINDOWS" -port 8889 -hubHost localhost

  2.4)通过json注册多个浏览器、版本、系统等信息到node
java -jar selenium-server-standalone-2.53.0.jar -role node -nodeConfig node-json-XXX.cfg.json

{
  "capabilities":
    [
      {
        "browserName": "firefox",
        "version": 43,
        "maxInstances": 5,
        "seleniumProtocol": "WebDriver"
      },
      {
        "browserName": "chrome",
        "version": 61,
        "maxInstances": 5,
        "seleniumProtocol": "WebDriver"
      },
      {
        "browserName": "iexplore",
        "version": 9,
        "maxInstances": 4,
        "seleniumProtocol": "WebDriver"
      }
    ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": localhost,
    "register": true,
    "registerCycle": 5000,
    "htbPort": 4444,
    "hubHost": localhost
  }
}


  2.5)启动Android的node
java -jar selenium-server-standalone-2.53.0.jar -role node -browser "seleniumProtocol=WebDriver, browserName=android, version=4.4.2, maxInstances=1, platform=ANDROID" -port 8899 -hubHost localhost

参考:http://www.cnblogs.com/zw520ly/p/5995708.html

原文地址:https://www.cnblogs.com/aikachin/p/7755109.html