Question

I am trying to test

In the grunt file

karma: {
   e2e: {
    configFile: 'karma-e2e.conf.js',
    singleRun: true
  }
},

Karma file is basically what Yeoman generated for me. Only change is I swithed Chrome for PhantomJS.
karma-e2e.conf.js:

// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
 module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
  'test/e2e/**/*.js'
],

// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
//   '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
 });
};

I have a very basic test I try to run

describe('E2E: Testing Routes:', function () {
'use strict';
beforeEach(function() {
    browser().navigateTo('/');
});

it('test', function() {
    browser().navigateTo('#/');
    expect(browser().location().path()).toBe("/list_persons");
});
})

This is the output from the test. I googled this error and it suggested that I add a "sleep" in my test. That does not sound like a solution for me.

> Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://local:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket i0eExVxerWfwrirxJXue with id 46269744
PhantomJS 1.9.7 (Linux): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.7 (Linux) E2E: Testing Routes: should jump to the /videos path when / is accessed FAILED
    TypeError: 'undefined' is not a function (evaluating '$document.injector()')
PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.068 secs / 0.077 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.

Can anyone help me. What I want to do is to run e2e tests from grunt in PhantomJS.It does not have to be on a listener for filechanges. One simple run on "grunt test" is perfect.

Edit: I changed files to include

files: [
    'app/vendor/scripts/angular.js',
    'app/vendor/scripts/angular-mocks.js',
    'app/vendor/scripts/angular-route.js',
    'app/vendor/scripts/jstd-scenario-adapter-config.js',
    'app/vendor/scripts/jstd-scenario-adapter.js',
    'app/vendor/scripts/angular-scenario.js',
    'test/e2e/**/*.js'
],

Now getting this:

Running "karma:e2e" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket ZbZbabDGNCtvVa4Z-LQk with id 99494524
PhantomJS 1.9.7 (Linux): Executed 0 of 0 ERROR (0.036 secs / 0 secs)
Warning: Task "karma:e2e" failed. Use --force to continue.
Was it helpful?

Solution

You have to add this:

singleRun: true,

To your karma config section in your grunt file.

Details:

https://github.com/karma-runner/grunt-karma

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top