【发布时间】:2013-09-04 00:18:44
【问题描述】:
我尝试使用 Grunt Karma 运行 E2E 测试,但没有成功。我看了很多解决方案,但没有一个有效!
我的 karma-e2e.conf.js:
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '../',
// frameworks to use
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
'test/e2e/**/*.js',
'test/e2e/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9877,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,
// Uncomment the following lines if you are using grunt's server to run the tests
proxies: {
'/': 'http://localhost/test/e2e/'
},
// URL root prevent conflicts with the site root
urlRoot: '/_karma_/'
});
};
PS:我的应用在端口 80(Apache 默认)上运行。
我的规格如下:
describe('E2E: Testing Routes:', function () {
'use strict';
beforeEach(function() {
browser().navigateTo('/');
});
it('should jump to the /videos path when / is accessed', function() {
browser().navigateTo('#/');
expect(browser().location().path()).toBe("/main");
});
})
所以,当我运行这个规范时,我收到了这条消息:
“类型错误:未定义不是函数(正在评估 $document.injector())”
此错误发生在“expect(browser().location().path()).toBe("/main");”行
有什么想法吗?
【问题讨论】:
-
我建议看看 Protractor,新的 AngularJS E2E 测试运行器。它仍在开发中,但与 Karma 和场景运行器相比,我遇到的问题更少。
-
我已经看到了这个解决方案,但是不起作用。
-
您是手动引导应用程序和/或使用 requirejs 吗?你能添加你的主 html 页面吗?
标签: angularjs gruntjs karma-runner angularjs-e2e