量角器“ - 失败:无法读取null的属性'ver'

问题描述 投票:0回答:2

在尝试启动测试时,我正面临着量角器的烦人问题。

量角器版本:5.1.2

protractor.conf.js

var SpecReporter = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:8080/src/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  useAllAngular2AppRoots: true,
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter());
  },  
  rootElement: '*[ng-app]',
};

端到端测试文件“app.comp.e2e-spec.js”

import { browser, element, by, $ } from 'protractor';

describe('testproject App', function() {

  it('should display message saying app works', (done) => {
    browser.get('/');
    expect($('.my-span').isPresent()).toBe(true);
    return done();
  });

});

每次我启动测试(protractor protractor.conf.js)我都会遇到这个错误信息:

1) testproject App should display message saying app works
- Failed: Cannot read property 'ver' of null

Executed 1 of 1 spec (1 FAILED) in 0.984 sec.
[11:27:52] I/launcher - 0 instance(s) of WebDriver still running
[11:27:52] I/launcher - chrome #01 failed 1 test(s)
[11:27:52] I/launcher - overall: 1 failed spec(s)
[11:27:52] E/launcher - Process exited with error code 1

我当然有一个运行在localhost:8080 / index的Angular应用程序,当使用浏览器手动访问时它可以正常工作。有人有任何想法解决这个问题吗?提前致谢

angular protractor e2e-testing
2个回答
0
投票

就我而言,在应用程序配置/加载期间触发了意外警报消息时引发了此错误。这是由于无法与外部系统通信而发生的,而外部系统仅发生在Travis CI中。由于这是唯一的错误消息,因此确定真正原因需要很长时间。 (尤里卡时刻是我跟着一个带有.then()的browser.get()调用,在正常错误处理程序和错误处理程序中进行了单独的故意失败的expect()测试;这个替换了'ver'失败,提供了更多信息和有用的信息有关意外警报的失败消息。)

解决方案是消除对外部系统的依赖性(首先不应该在测试配置中)。


-1
投票
expect($('.my-span').isPresent()).toBe(true);

isPresent()返回Promise不为true或false。

要检查元素是否存在,请使用promise返回的值:

element(anyFinder).isPresent().then(function(isPresent) {
  if ( isPresent) {
   // The element is present
  } else {
  // The element is not present
}
});
© www.soinside.com 2019 - 2024. All rights reserved.