【问题标题】:Run PhantomJS and Chrome browser on the same Selenium grid node在同一个 Selenium 网格节点上运行 PhantomJS 和 Chrome 浏览器
【发布时间】:2018-05-28 12:33:55
【问题描述】:

我有一个 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

【问题讨论】:

  • 在节点启动时发现:14:37:48.396 INFO - 找不到驱动程序类:org.openqa.selenium.phantomjs.PhantomJSDriver
  • 发现在 selenium 独立服务器版本 3.8.1 上,类路径中没有 PhantomJSDriver。 3.7.1 版本一切正常

标签: java selenium selenium-webdriver selenium-grid


【解决方案1】:

虽然您已经为 PhantomJS 定义了capabilities,如下所示;

capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.PHANTOMJS);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.MAC);

但是当new RemoteWebDriver(new URL(hubURL), capabilities); 被调用时,我看不到那些capabilities 被传递,因为 DesiredCapabilities capabilities 是在稍后阶段定义的。你能试试这个代码块吗:

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

【讨论】:

  • 我不小心按错误的顺序复制了代码。问题出在 selenium 网格独立服务器 jar 的版本上。看起来他们在 PhantomJSDriver 的 3.8.1 和 3.8.0 版本上有一个错误
猜你喜欢
  • 2019-08-13
  • 2018-08-20
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
  • 2019-11-10
  • 1970-01-01
相关资源
最近更新 更多