在同一个Selenium网格节点

时间:2017-12-14 12:07:42

标签: java selenium selenium-webdriver selenium-grid

我有一个Selenium网格集群包括1个集线器和多个节点。我想在所有节点上运行多个Chrome实例和多个PhantomJS实例。

我有以下节点的配置文件:

    {
  "capabilities":
  [
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "phantomjs",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

要运行该节点,我使用:

java -Dphantomjs.binary.path="ghostdriver" -Dwebdriver.chrome.driver=chromedriver -Dwebdriver.gecko.driver=geckodriver -jar selenium-server-standalone-3.8.1.jar -role node -hub http://{myIp}:4444/grid/register/ -nodeConfig "/Users/myUser/Desktop/selenium/nodeConfig.json"

我已成功连接到Chrome远程驱动程序:

String hubURL = "http://localhost:4444/wd/hub";
ChromeOptions chromeOptions = new ChromeOptions();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);

但是,在尝试连接到PhantomJS远程驱动程序时,我仍然可以获得具有Chrome功能的Chrome浏览器

capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);
DesiredCapabilities capabilities = new DesiredCapabilities();
RemoteWebDriver driver = new RemoteWebDriver(new URL(hubURL), capabilities);

从网格控制台我可以看到所有浏览器都可用(包括PhantomJS)grid console

我做错了什么?

修改

问题是在Selenium服务器版本3.7.1

之前支持PhantomJS

1 个答案:

答案 0 :(得分:1)

虽然您已为{strong> "a", "b", "c" 定义capabilities,但如下所示;

PhantomJS

但是,在调用capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS); capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC); 时,我看不到那些capabilities被传递,因为 new RemoteWebDriver(new URL(hubURL), capabilities); 是在稍后阶段定义的。你能试试这个代码块吗?

DesiredCapabilities capabilities