【问题标题】:I'm not able to run protractor test in firefox but in chrome it runs fine我无法在 Firefox 中运行量角器测试,但在 chrome 中运行良好
【发布时间】:2019-10-09 19:39:00
【问题描述】:

当我尝试在 Firefox 中运行 Protractor e2e 测试时,它会启动浏览器,但我的测试脚本没有被执行。

我使用的是 windows Server 2012 R2 机器,firefox 版本 46.0.1 和 Selenium 2.53.0。

它给了我以下错误:

Using FirefoxDriver directly...
[launcher] Running 1 instances of WebDriver

code\ui\dgui\node_modules\protractor\node_modules\selenium-webdriver\http\util.js:89
          Error('Timed out waiting for the WebDriver server at ' + url));
          ^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:58798/hub

我尝试独立运行 Selenium

    code\ui\dgui\node_modules\protractor\selenium>java -jar selenium-server-standalone-2.53.0.jar
    09:37:21.214 INFO - Launching a standalone Selenium Server
    09:37:21.285 INFO - Java: Oracle Corporation 25.91-b14
    09:37:21.285 INFO - OS: Windows Server 2012 R2 6.3 amd64
    09:37:21.293 INFO - v2.53.0, with Core v2.53.0. Built from revision 35ae25b
    09:37:21.332 INFO - Driver class not found: com.opera.core.systems.OperaDriver
    09:37:21.332 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
    09:37:21.336 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
    registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN8
    09:37:21.336 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
    09:37:21.336 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
09:37:21.434 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:37:21.434 INFO - Selenium Server is up and running

我正在使用npm run e2e 命令来执行我的测试

我的配置文件:

exports.config = {

  allScriptsTimeout: 30000,

  suites: {
      test Suit: 'e2e/TestSuites/Tests/*.js',
  },

   multiCapabilities: [

    // We will want to eventually include the following options to split out tests to multiple instances

    {'browserName': 'firefox'}
  ],


  // only for firefox and chrome - IE will require using a selenium server

  directConnect : true,  

  // make sure that the baseURL reflects the configuration of the web server

  baseUrl: 'http://10.26.5.13:8000/',


  framework: 'jasmine2',

  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000
  },


  onPrepare: function() {     
    var jasmineReporters = require('jasmine-reporters');

    browser.driver.manage().window().maximize();

    return browser.getProcessedConfig().then(function(config) {

      var browserName = config.capabilities.browserName;


      var junitReporter = new jasmineReporters.JUnitXmlReporter({
             consolidateAll: true,
             savePath: 'tests/test-results',
             // this will produce distinct xml files for each capability
             filePrefix: browserName + '-xmloutput',
             modifySuiteName: function(generatedSuiteName, suite) {
                 // this will produce distinct suite names for each capability,
                 // e.g. 'firefox.login tests' and 'chrome.login tests'
                 return browserName + '.' + generatedSuiteName;
             }

         });
         jasmine.getEnv().addReporter(junitReporter);
    });    

  }, 

  resultJsonOutputFile: 'tests/test-results/output.json'

};

【问题讨论】:

  • 是因为 selenium 独立运行 127.0.0.1:4444/wd/hub 并且量角器正在 127.0.0.1:58798/hub 搜索 WebDriver 服务器
  • 如果是这样,我如何在 Protractor 中更新 WebDriver 服务器位置
  • 我的配置文件:multiCapabilities: [ {'browserName': 'firefox'}, // {'browserName': 'chrome'} ], directConnect : true,
  • 如果您使用的是directConnect,则根本不应该访问 selenium 服务器。你确定你的配置被正确提取了吗?你能编辑你的问题并包括你的整个配置文件和你用来启动量角器的命令吗?
  • @NickTomlin 包含了我的配置文件。

标签: protractor


【解决方案1】:

找到这个链接:https://github.com/angular/protractor/issues/3182,

我也遇到了类似的问题。

我尝试安装 Firefox v44.0.2,然后执行我的脚本,它成功了。

我之前使用的是 Firefox v46,但我的脚本没有使用 Firefox v46 执行。

【讨论】:

  • 如果您在 2016 年遇到此问题,请尝试将 firefox 更新到最新版本,最好是 v47.0.1,您的量角器测试应该会再次运行;从今天起无需使用旧版本:)
  • 嗨@pelican 我试过使用 Firefox v47.0.1,它会启动浏览器,但我的脚本不会执行。我得到以下错误:C:\Local_E2E\analytics-qa\TestAutomation\SeleniumFramework\node_modules\protractor\node_modules\selenium-webdriver\http\util.js:89 Error('Timed out waiting for the WebDriver server at ' + url)); ^ Error: Timed out waiting for the WebDriver server at http://127.0.0.1:64870/hub at Error (native) at onResponse (C:\Local_E2E\analytics-k\node_modules\protractor\node_modules\selenium-webdriver\http\util.js:89:11)
  • 您可能需要使用此命令“webdriver-manager update”更新您的 webdriver 服务器 jar 和 chrome 驱动程序 - 您的可能是旧版本。另请查看此链接,展示您遇到的相同问题和各种解决方案:“github.com/angular/angular-phonecat/issues/276”。最后,通常只需用谷歌搜索你得到的错误,你可能会惊讶于其他人遇到同样的问题并将问题发布在网上某个地方。
  • 感谢@pelican 这有帮助,我将量角器版本更新为 4.0.2,并在 Firefox 最新版本上进行了测试。我使用的是旧量角器版本。
【解决方案2】:

firefox 49.0.2 和 Selenium 2.52.0 也有同样的问题 我安装了 Firefox 便携式 46,一切都对我有用。

我在 protractor.config 文件中设置:

...
    capabilities: {
    // FIREFOX portable in version 46.0.1
    'browserName': 'firefox',
    "firefox_binary": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe",
    "binary_": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe"
},
// tells protractor to directly connect to the webdriver
directConnect: true
...

我在这里下载了 Firefox Portable:http://www.m64.info/index.php/firefox-64-bit-portable 这也是一个“安装”多个版本的 Firefox 的好机会 :-) 希望有人会帮助它!

【讨论】:

    【解决方案3】:

    在此处按照量角器设置: http://www.protractortest.org/#/tutorial#setup

    这些版本对我有用:

    Node: v6.9.4
    NPM: v3.10.10
    Protractor: v5.1.0
    Selenium WebDriver: 3.0.1
    Firefox: 51.0.1
    

    conf.js:

    exports.config = {
      framework: 'jasmine',
      // no need for seleniumAddress for firefox and chrome
      specs: ['spec.js'],
      capabilities: {
        browserName: 'firefox',
        firefoxPath: 'C:/Program Files/Mozilla Firefox/firefox.exe'
      },
      directConnect: true // for firefox and chrome
    }
    

    https://github.com/angular/protractor/blob/master/lib/config.ts

    【讨论】:

      【解决方案4】:

      将二进制 (firefox.exe) 位置添加为 moz:firefoxOptions 功能

      exports.config = {   
      
         capabilities: {
              browserName: 'firefox',
              shardTestFiles: false,
              'moz:firefoxOptions': {
          'binary': "<your_path>/Mozilla Firefox/firefox.exe"
        }
          },
      

      【讨论】:

        猜你喜欢
        • 2019-12-22
        • 2017-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-25
        • 1970-01-01
        • 2019-11-08
        相关资源
        最近更新 更多