2
votes

I tried to run E2E tests with Grunt Karma, but no success. I've look many solutions, but no one worked!

My 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: My app run at port 80 (Apache default).

My spec is as follows:

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");
});

})

So, when a I ran this spec, I got this message:

"Type Error: undefined is not a function (evaluating $document.injector())"

This error occurs at line "expect(browser().location().path()).toBe("/main");"

Any idea?

2
I advise to look at Protractor, the new AngularJS E2E tests runner. It's still in development, but I had less issues with it than Karma and scenario-runner. - Klaster_1
I already saw this solution, but doesn't work. - vitorvigano
Are you bootstrapping the app manually and/or using requirejs? Could you add your main html page? - lorcan

2 Answers

0
votes

Make sure your running your web server an also karma. Try changing your proxy settings to something like this:

    proxies: {
    '/': 'http://localhost:8000/'
    },
0
votes

You need

 plugins: [
      'karma-ng-scenario',
    ],

in your config file.

Do npm install karma-ng-scenario --save-dev first