我一直试图解决这个问题,但现在还没有运气。我正在使用karma和ng-Scenario进行E2E(端到端)测试,以便在服务器上运行我的角度应用程序。我知道有一个更强大的工具(Protractor)可用于端到端测试,但出于某种原因我只能使用ng-scenario。 我通过karma服务器代理我的应用程序的IP地址,如下面的Karma配置文件中所示。
我在Chrome浏览器和控制台上收到错误$document.injector is not a function
。我怀疑可能导致问题的一件事是应用程序在加载后获取所有数据(它是单页应用程序)。但是不知道天气实际上是问题背后的问题。
其次,我的应用程序的端口被重定向,这可能导致问题。
或者第三,我认为网络网关路由(我的系统的IP)可能存在一些问题。
我的业力配置文件
module.exports = function(config) {
config.set({
basePath : '../',
files : [
'app/lib/angular/angular.js',
'bower_components/angular-1.3.15/angular-mocks.js',
'test/e2e/application/scenarios.js',// or 'test/e2e/**/*.js'
],
autoWatch : true,
urlRoot : '/__karma/',
browsers : ['Chrome'],
frameworks : ['ng-scenario'],
singleRun : false,
proxies : {
'/' : 'http://10.10.5.56:0080/',
},
reporters : [ 'progress', 'htmlalt'],
logLevel: config.LOG_DEBUG,
plugins : [
'karma-jquery',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-ng-scenario',
'karma-htmlfilealt-reporter',
'karma-mocha',
'karma-chai',
'karma-phantomjs-launcher',
'karma-jasmine-matchers',
'karma-bdd-using',
],
htmlReporter : {
outputFile : 'output/E2E.html',
// Optional
pageTitle : 'End to End',
subPageTitle : 'Karma-Jasmine Automation Test Framework Report'
},
})}
我的方案文件
'use strict';
describe('Application Login and Logout', function() {
var spyEvent;
beforeEach(function() {
browser().navigateTo('../index.html');
console.log("Something in beforeEach");
});
// test default route
it('should navigate to correct page', function() {
console.log("Something in IT before expect");
expect(browser().location().path()).toBe('/login');
console.log("Something in IT after expect");
});
it('User is able to login application with valid credentials', function() {
console.log("Something again");
expect(browser().location().path()).toContain("/login");
input('username').enter('motzieadmin@qasource.com');
input('password').enter('admin');
element('button').click();
expect(browser().location().path()).toContain("/home");
});
});
我遇到的错误
browser navigate to '../index.html'
11ms $location.path()
http://localhost:9876/base/test/e2e/application/scenarios.js:13:10
TypeError: $document.injector is not a function
at ChildScope.<anonymous> (http://localhost:9876/base/node_modules/karma-ng-scenario/lib/angular-scenario.js:27819:30)
at angular.scenario.Application.<anonymous> (http://localhost:9876/base/node_modules/karma-ng-scenario/lib/angular-scenario.js:27698:18)
at angular.scenario.Application.executeAction (http://localhost:9876/base/node_modules/karma-ng-scenario/lib/angular-scenario.js:26854:19)
at ChildScope.<anonymous> (http://localhost:9876/base/node_modules/karma-ng-scenario/lib/angular-scenario.js:27671:22)
我不知道自己做错了什么。路径可能存在一些问题。感谢帮助。