Selenium的默认配置文件和创建自己的配置文件

launch

  • selenium 的 launch 方法是在 GridLauncherV3 类的 main 方法
org.openqa.grid.selenium.GridLauncherV3#main
  • 在该类的 buildLaunchers 中 可以找到配置 hub 的配置类和 Node 的配置类

Hub配置类

  • Hub 的配置类是 GridHubConfiguration,进入类中可以看到默认的配置文件路径:
   public static final String DEFAULT_HUB_CONFIG_FILE = "org/openqa/grid/common/defaults/DefaultHub.json";
    private static HubJsonConfiguration DEFAULT_CONFIG_FROM_JSON = HubJsonConfiguration.loadFromResourceOrFile("org/openqa/grid/common/defaults/DefaultHub.json");
  • 打开 org/openqa/grid/common/defaults/DefaultHub.json 文件,可以看到以下默认配置:
{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "registry": "org.openqa.grid.internal.DefaultGridRegistry",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

Node配置类

  • Node的配置类是 GridNodeConfiguration,进入该类可以找到默认的配置文件:
    public static final String DEFAULT_NODE_CONFIG_FILE = "org/openqa/grid/common/defaults/DefaultNodeWebDriver.json";
    private static NodeJsonConfiguration DEFAULT_CONFIG_FROM_JSON = NodeJsonConfiguration.loadFromResourceOrFile("org/openqa/grid/common/defaults/DefaultNodeWebDriver.json");
  • 进入 org/openqa/grid/common/defaults/DefaultNodeWebDriver.json 文件,可以看到以下默认配置:
{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "marionette": true,
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "internet explorer",
      "platform": "WINDOWS",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "safari",
      "technologyPreview": false,
      "platform": "MAC",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": -1,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

修改配置文件

  • 有了以上的两个配置文件,可以根据自己的需求做修改,可以实现自己的DefaultRemoteProxy类等其他类,也可以修改默认的值。

启动

  • 在启动时 hub 节点添加 -hubConfig 参数,值为修改配置文件路径,node 节点添加 -nodeConfig 参数,值为修改配置文件路径,如下所示:
-role hub -hubConfig config\DefaultHub.json 
-role node -nodeConfig config\DefaultNodeWebDriver.json
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值