0

从一个月开始,我一直在尝试解决这个问题,但还没有运气。我正在使用 karma 和 ng-Scenario 为我在服务器上运行的 Angular 应用程序进行 E2E(端到端)测试。我知道有一个更强大的工具(量角器)可用于端到端测试,但出于某种原因,我只能使用 ng-scenario。我正在通过业力服务器代理我的应用程序的 IP 地址,如下所示在我的业力配置文件中。


$document.injector is not a function的 chrome 浏览器和控制台出现错误。我怀疑可能导致问题的一件事是应用程序在加载后获取所有数据(这是一个单页应用程序)。但不知道天气这实际上是否是问题背后的问题。

其次,我的应用程序的端口正在被重定向,这可能会导致问题。

或者第三我认为,可能是网络网关路由(我的系统的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)

我不知道我做错了什么。路径可能有问题。帮助表示赞赏。

4

0 回答 0