【问题标题】:Java Selenium error with Firefox-PortableFirefox-Portable 的 Java Selenium 错误
【发布时间】:2019-07-22 14:22:05
【问题描述】:

在将我们严重过时的 FirefoxPortable 更新到最新版本 68.0.1 后,我正在努力让我们的集成测试恢复并运行。 据了解,我使用了 geckodriver。但我不断收到以下消息。

错误:

org.openqa.selenium.SessionNotCreatedException(Unable to find a matching set of capabilities
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_171'
Driver info: driver.version: FirefoxDriver

代码:

    if (OS.isFamilyWindows()) {

        FirefoxBinary binary =
                new FirefoxBinary(new File(binPath + "/firefoxWindows/FirefoxPortable.exe"));
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setCapability("marionette", true);
        System.setProperty("webdriver.gecko.driver", binPath + "/geckoWindows/geckodriver.exe");
        firefoxOptions.setBinary(binary);
        ffDriver = new FirefoxDriver(firefoxOptions);
    }

我们的集成测试将在共享的 Linux Jenkins 测试服务器上执行。目前我使用的是 Windows。

我想继续使用便携式版本的 Firefox,以防止与使用同一台机器的其他团队发生冲突。不幸的是,安装 Docker 也是没有选择的。

我们正在使用 Java.version: '1.8.0_171',我们发布得太晚了,无法切换到更高版本。

我应该切换到 Chrome 吗?

我需要一个快速的解决方案,谢谢。

【问题讨论】:

    标签: java selenium firefox marionette geckodriver


    【解决方案1】:

    当您使用 FirefoxPortable v68.0.1 时,可能您使用的是最新版本的 Selenium v​​3.141.59,因此必须使用 GeckoDriver。据观察,在 ma​​rionette 的帮助下使用以下代码块 GeckoDriver 能够启动 FirefoxPortable v68.0.1 浏览器,但很快就会崩溃一个错误。

    • 代码块:

      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.firefox.FirefoxOptions;
      
      
      public class A_Portable_Firefox {
      
          public static void main(String[] args) {
      
              System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
              FirefoxOptions options = new FirefoxOptions();
              options.setBinary("C:\\FirefoxPortable\\FirefoxPortable.exe");
              WebDriver driver =  new FirefoxDriver(options);
              driver.get("https://stackoverflow.com");
              System.out.println("Page Title is : "+driver.getTitle());
              driver.quit();
          }
      }
      
    • 错误堆栈跟踪:

      Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
      Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
      System info: host: 'DEBANJAN', ip: '192.168.1.125', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_172'
      Driver info: driver.version: FirefoxDriver
      
    • 浏览器快照:


    分析

    根据GeckoDriver v0.23.0 is unable to initiate a new session through FirefoxPortable@andreastt 的讨论明确提到:

    恐怕 geckodriver 不支持 Firefox Portable。

    @whimboo 进一步补充:

    如果启动画面(或它是什么)阻止了 Firefox 完全启动,那么 Marionette 将不会被启用。

    【讨论】:

    • 有没有我可以使用的替代方案,不需要在测试服务器上拥有管理权限?
    • @Jonas_Hess 理想情况下,Selenium 测试应该使用非 root 用户/权限执行。
    • 是的,但我无法在测试服务器上安装浏览器。所以我希望找到一个不需要我这样做的解决方案。
    • 在外部设备上安装 Portable Firefox Browser,例如笔式驱动器或外部硬盘并继续执行测试。
    • 但是你刚才说不支持FirefoxPortable,会报错。这并不是说我无权访问文件系统。我只是不能在那台机器上安装额外的浏览器,所以我想使用便携式浏览器,因为使用它不需要 root 权限。有没有办法通过便携式浏览器启动和运行 selenium?
    【解决方案2】:

    如果你是通过 linux 服务器上的 jenkins 运行测试,即 jenkins 在 linux 机器上执行测试,你需要在 firefox 的 headless 模式下运行测试。

    另外你需要在linux机器上安装xvfb。

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 2018-04-04
      • 2015-09-26
      • 2017-08-30
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多