angularjs量角器3.3.0不报告规格

时间:2016-06-26 23:38:56

标签: javascript angularjs jasmine protractor e2e-testing

我没有看到传递的运行的预期输出,断言未列出。我希望在这一行中看到断言“1规格,0失败”。

输出:

  [18:28:06] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
  [18:28:06] I/launcher - Running 1 instances of WebDriver
  Started
  .


  1 spec, 0 failures
  Finished in 0.854 seconds
  [18:28:08] I/launcher - 0 instance(s) of WebDriver still running
  [18:28:08] I/launcher - chrome #01 passed

在量角器网站上看到的预期运行结束输出http://www.protractortest.org/#/“运行测试”):

  1 test, 3 assertions, 0 failures

规范:

  describe('Viewing index.html', function() {
  'use strict';


   beforeEach(function(){
     browser.get('/');
   });

   it('should have pages in left nav', function() {
      expect(element.all(by.repeater('page in adminClient.selectedSite.pages')).count()).toBeGreaterThan(0);
    });

  });

我验证了by.repeater定位器的工作原理:

  element.all(by.repeater('page in adminClient.selectedSite.pages')).count()
         .then(function(count){
            console.log('page count: ' + count);
      });

[更新]根据这个SO,这是一个版本问题,并建议在onPrepare钩子上注入jasmine记者,但这给我带来了更多的运行时错误。 stack overflow question

我的量角器配置:

  exports.config = {
    allScriptsTimeout: 11000,
    chromeOnly: true,
    chromeDriver: 'node_modules/protractor/bin/selenium/chromedriver_2.21',
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['tests/e2e/*-spec.js'],
    capabilities: {
      'browserName': 'chrome'
    },
    baseUrl: 'http://localhost:8889/',
    framework: 'jasmine',
    jasmineNodeOpts: {
      showColors: true,
      defaultTimeoutInterval: 30000
    }
  };

1 个答案:

答案 0 :(得分:1)

要查看规范名称和断言,您必须将--verbose标志传递给量角器。如果您使用grunt或其他东西来运行量角器,您需要在配置中指定此标志。

修改 阅读完编辑后,我相信我找到了解决您问题的方法。我已经用自己的项目尝试了它,它似乎有效。

潜在的问题是你可能正在使用量角器3,它不再支持许多以前的选项,特别是在jasmineNodeOpts内。要解决此问题,您应该将量角器的版本降级为2,最新版本为2.5.1

Here's the related issue on protractor's github repository。它也像你所说的那样在onPrepare钩子中提到了一个自定义记者,但是另一个:jasmine-spec-reporter。我得到的结果与你使用的配置略有不同,但它没有显示断言,只是有更好的测试输出,我非常喜欢:

jasmineNodeOpts: {
  print: function () {} // remove dots for each test
},

onPrepare: function () {
    var SpecReporter = require('jasmine-spec-reporter');
    jasmine.getEnv().addReporter(new SpecReporter({displayStackTrace: true}));
}