Last Updated: February 25, 2016
·
3.799K
· skeep

Running E2E for Yeoman generated angular app

Yeoman is a great tool. It gives build tool, dependancy management and unit test runner out of the box.

But there is no straight way to run the angular E2E test. It needs little bit of configuration. Below are the steps that I do to run E2E test.

  • Yeoman automatically generate karma-e2e.conf.js file. We need to modify it a little bit according to our own requirement. This is what I do.

Uncomment below lines

// 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_';
  • Change singleRun = false; to singleRun = true;
  • you also have to create a folder to keep your e2e test file. I typically create a folder e2e under /test
  • If you are using coffeescript to write you test cases you need to do this step, otherwise you are done. To allow preprocessing of coffeescript do the following:

change

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'test/e2e/**/*.js'
]

to

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'test/e2e/**/*.coffee'
];

and you also need to tell karma to preprocess the files. add below code in the file

preprocessors = {
  'test/e2e/**/*.coffee': 'coffee'
};

You are done changing the file. To run the step you need to start the server in one terminal and then run the test.

To start the server do:

$ grunt server

Then open a new terminal and execute

$ karma start  karma-e2e.conf.js

It should execute the end to end test cases. To write E2E test using angular scenario runner you need to have a look at the http://docs.angularjs.org/guide/dev_guide.e2e-testing