org.openqa.selenium.WebDriverException:转发新会话时找不到错误:功能{acceptInsecureCerts:对于Firefox为true

时间:2018-09-03 19:13:59

标签: java selenium firefox selenium-grid geckodriver

我安装了Windows 10-64,Firefox 61.0.2,Java。我正在使用selenium-grid和selenium-server-standalone-3.11.0.jar和geckodriver 21.0执行测试,但是当我运行它时,测试显示以下错误:

  

org.openqa.selenium.WebDriverException:转发新的错误   会话找不到:功能{acceptInsecureCerts:是的,   browserName:firefox,平台:WINDOWS,版本:61.0.2}

我的代码:

private void createBrowserInstance() throws MalformedURLException {
    switch (environmentHandler.getTestBrowser().toLowerCase()) {
        case "firefox":
            FirefoxOptions firefox  = new FirefoxOptions();
            firefox.setCapability("marionette", false);
            browCapab = DesiredCapabilities.firefox();
            browCapab.setBrowserName("firefox");
            browCapab.setPlatform(Platform.WINDOWS);
            browCapab.setVersion("61.0.2");

2 个答案:

答案 0 :(得分:3)

Error forwarding the new session cannot find是网格告诉您的方式,它找不到与您请求的功能匹配的节点。

网格使用以下4个属性进行能力匹配[将测试用例中请求的能力与节点必须提供的实际能力进行匹配]

  • 浏览器名称
  • 平台
  • 版本
  • 应用程序名称(此AFAIK未记录,但确实存在。请参阅here

您没有提到如何启动节点。具体来说,您没有提到是否使用节点配置JSON文件(此配置文件通常用于调整节点支持的功能等)。但我假设您没有使用。

在没有任何其他自定义的情况下启动节点时,则它不知道version的功能。

因此,它可能会有一个节点可以支持firefox上的windows。但是您的测试正在寻找在firefox version 61.0.2上运行的windows。这说明了错误。

要解决此问题,您可以执行以下操作之一:

  • 从测试代码中删除行browCapab.setVersion("61.0.2");(或)
  • 在启动节点时使用节点配置文件中的版本信息。

    要了解如何使用节点配置文件,可以参考我的博客文章here

答案 1 :(得分:1)

此错误消息...

org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {acceptInsecureCerts: true, browserName: firefox, platform: WINDOWS, version: 61.0.2}

...表示 GeckoDriver 无法转发新会话。

您的主要问题是所使用的配置中的不兼容性,如下所示:

  • 根据您所使用的问题:
    • selenium-server-standalone-3.11.0.jar
    • geckodriver 21.0
  • 因此,您必须强制使用功能木偶。要实现这一目标:

    • 您可以保留功能木偶,因为默认情况下marionette设置为
    • 您还可以如下指定功能木偶

      FirefoxOptions firefox_options  = new FirefoxOptions();
      firefox_options.setCapability("marionette", true);
      
  • firefox 是关键字/保留字,因此请勿在测试中使用此术语。

  • 其余代码看起来不错。
  • 根据WebDriver W3C Editor's Draft
    • browserName:如果value不等于匹配功能中“ browserName”条目的字符串,则返回成功,数据为null。
    • browserVersion:使用实现定义的比较算法,将值与匹配功能中的“ browserVersion”条目进行比较。比较是接受一个值,该值使用“ <”,“ <=“,”>”和“> =”运算符对版本施加约束。如果两个值不匹配,则返回成功,数据为空。
    • platformName:如果value不等于匹配功能中“ platformName”条目的字符串,则返回成功,数据为null。
  • 您可以在org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities
  • 中找到相关的讨论