【问题标题】:Angular Karma e2e with GruntAngular Karma e2e 与 Grunt
【发布时间】:2014-03-22 19:08:21
【问题描述】:

我正在尝试测试

在 grunt 文件中

karma: {
   e2e: {
    configFile: 'karma-e2e.conf.js',
    singleRun: true
  }
},

Karma 文件基本上是 Yeoman 为我生成的文件。唯一的改变是我为 PhantomJS 更换了 Chrome。
业力-e2e.conf.js:

// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
 module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
  'test/e2e/**/*.js'
],

// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
//   '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
 });
};

我尝试运行一个非常基本的测试

describe('E2E: Testing Routes:', function () {
'use strict';
beforeEach(function() {
    browser().navigateTo('/');
});

it('test', function() {
    browser().navigateTo('#/');
    expect(browser().location().path()).toBe("/list_persons");
});
})

这是测试的输出。我用谷歌搜索了这个错误,它建议我在测试中添加“睡眠”。这对我来说听起来不是一个解决方案。

> Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://local:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket i0eExVxerWfwrirxJXue with id 46269744
PhantomJS 1.9.7 (Linux): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.7 (Linux) E2E: Testing Routes: should jump to the /videos path when / is accessed FAILED
    TypeError: 'undefined' is not a function (evaluating '$document.injector()')
PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.068 secs / 0.077 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.

谁能帮帮我。我想要做的是从 PhantomJS 中的 grunt 运行 e2e 测试。它不必在文件更改的侦听器上。对“grunt test”进行一次简单的运行是完美的。

编辑:我更改了文件以包含

files: [
    'app/vendor/scripts/angular.js',
    'app/vendor/scripts/angular-mocks.js',
    'app/vendor/scripts/angular-route.js',
    'app/vendor/scripts/jstd-scenario-adapter-config.js',
    'app/vendor/scripts/jstd-scenario-adapter.js',
    'app/vendor/scripts/angular-scenario.js',
    'test/e2e/**/*.js'
],

现在得到这个:

Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket ZbZbabDGNCtvVa4Z-LQk with id 99494524
PhantomJS 1.9.7 (Linux): Executed 0 of 0 ERROR (0.036 secs / 0 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.

【问题讨论】:

  • 有些奇怪。错误消息提到 /videos,但您的两个来源都不包含此 url。否则,您似乎应该将角度框架文件添加到文件部分。看起来它没有找到框架功能。关于 grunt 我添加了一个答案,但它只关注 grunt 部分。
  • URL 是本地主机。我必须这样做才能在此处发布它
  • 我的意思是这部分:文件:['test/e2e/**/*.js'],也应该包含角度框架模块。
  • 你是对的。从我的凉亭组件场景文件夹中。我有 angular-scenario.js、jstd-scenario-adapter.js 和 jstd-scenario-adapter.config。包括第一个很明显,但其他两个?

标签: angularjs gruntjs karma-runner angular-scenario


【解决方案1】:

你必须添加这个:

singleRun: true,

到您的 grunt 文件中的 karma 配置部分。

详情:

https://github.com/karma-runner/grunt-karma

【讨论】:

  • 谢谢,但更改对我的错误完全没有影响。
  • 是的。这仅来自正确连接 grunt/karma。 (“主要” cmets 反对错误...)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-21
相关资源
最近更新 更多