【问题标题】:How can I configure the firefox binary location in Protractor?如何在 Protractor 中配置 firefox 二进制位置?
【发布时间】:2021-06-09 08:19:10
【问题描述】:

我正在使用 Chrome 成功运行 Protractor 测试,使用我的 Protractor 配置中的以下部分指定我的 chrome 二进制文件的路径:

capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE
'browserName': 'chrome',
"chromeOptions": {
  binary: 'C:/BuildSoftware/Chrome/Application/chrome.exe',
}

这行得通。

我的 Firefox 也安装在非标准位置。

是否有等效的方法在量角器配置中为 Firefox 指定二进制文件?

【问题讨论】:

    标签: angularjs windows testing firefox protractor


    【解决方案1】:

    已更新:请参阅下面的更新答案:https://stackoverflow.com/a/28313583/800699

    看来您必须使用 Firefox 驱动程序的自定义参数自行启动 Selenium 服务器。 见Protractor test is not starting on Firefox

    firefox 驱动程序的更多选项(包括自定义 firefox 二进制位置)可以在这里找到: https://code.google.com/p/selenium/wiki/FirefoxDriver

    P/S:浏览 Firefox 驱动程序源会发现更多亮点: https://code.google.com/p/selenium/source/browse/javascript/node/selenium-webdriver/firefox/index.js

    您可以尝试添加:

    "browserName": "firefox",
    "firefox_binary": "path/to/custom/firefox",
    "binary_": "path/to/custom/firefox"
    

    【讨论】:

    【解决方案2】:

    Protractor 现在支持在使用“直接连接”(即,没有 selenium 服务器)时直接在配置文件中设置 firefoxPath。查看参考配置文件:

    https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L67

    在顶级配置文件中添加firefoxPath。它是一个字符串,应该是您的 firefox 二进制文件的路径。您还需要在配置中使用directConnect: true

    有关更多详细信息(便于立即查看所有更改的文档),请查看the change that added this support (in Oct 2014)

    【讨论】:

      【解决方案3】:

      现在是 2018 年,您似乎可以在功能的 'moz:firefoxOptions' 部分中设置特定的 binary 参数,如下所示:

      capabilities: {
          browserName: 'firefox',
          'moz:firefoxOptions': {
              args: [...Your args here...],
              binary: '/Path/To/Custom/firefox'
          }
      }
      

      免责声明:我也在量角器配置中使用directConnect: true 运行了这个。如果您将命令传递给 Selenium 服务器,我不确定它是否有效。

      参考:https://github.com/mozilla/geckodriver/blob/master/README.md#mozfirefoxoptions

      【讨论】:

        【解决方案4】:

        我将自定义二进制位置添加到 PATH 变量中。

        export PATH="/custom-firefox-location:$PATH"
        

        这使我的自定义 firefox 版本在会话期间可用,并且在运行量角器时它会使用它。

        【讨论】:

          【解决方案5】:

          详细说明 Monkpit 的 答案是正确的。以下代码适用于我,在量角器 v 5.4.2 中验证和测试。 由于我在程序文件中安装了Firefox,因此只需通过管理员模式打开cmd以避免权限错误。

           capabilities: {
                browserName: 'firefox',
                'moz:firefoxOptions': {
                      args: ['--verbose'],
                      binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
                 //Need to start cmd via admin mode to avoid permission error
                  }
          },   
              Full code 
          
          exports.config = {
            framework: 'jasmine',
            directConnect: false, //Start protractor without start the selenium server using webdriver-manager start. default value is fales
            //This is  only for chrome and firefox and use drivers instead of selenium server
          
            capabilities: {
                browserName: 'firefox',
                'moz:firefoxOptions': {
                      args: ['--verbose'],
                      binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
                 //Need to start cmd via admin mode to avoid permission error
                  }
          },   
              //set to true So each spec will be executed in own browser instance. default value is false
              //restartBrowserBetweenTests: true,
               jasmineNodeOpts: {
              //Jasmine provides only one timeout option  timeout in milliseconds don't add ;
              defaultTimeoutInterval: 180000
               },
          
            seleniumAddress: 'http://localhost:4444/wd/hub',
            specs: ['src/com/sam/scriptjs/iframes.spec.js']
          
          }
          

          【讨论】:

            猜你喜欢
            • 2017-05-21
            • 1970-01-01
            • 2016-01-24
            • 2018-04-30
            • 2017-06-24
            • 2020-10-03
            • 1970-01-01
            • 2017-06-06
            • 1970-01-01
            相关资源
            最近更新 更多