$document.injector is not a function in Karma E2E Tests

118 Views Asked by At

I have been trying to resolve this from a month now but no luck yet. I am doing E2E(End-to-End) testing using karma and ng-Scenario for my angular application running on server. I know there is a more robust tool(Protractor) available for end to end testing but for some reason I have to use ng-scenario only. I am proxing the IP address of my application though karma server as shown below in my Karma config file.


I am getting error $document.injector is not a function on my chrome browser as well as in console. One thing which I doubt might be causing problem is that the app is getting all the data once it loads(It's a single page application). But don't know weather it is actually the problem behind the issue or not.

Secondly the port of my application is being redirected which may be causing the issue.

Or Thirdly I think, may be there's some problem with network gateway route(My system's IP).

My karma Config File

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'
    },

})}

My Scenarios File

'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('[email protected]');
        input('password').enter('admin');
        element('button').click();

        expect(browser().location().path()).toContain("/home");

    });
});

The Error I am getting

    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)

I don't know what am I doing wrong. There may be some problem with path. Help is appreciated.

0

There are 0 best solutions below