Last Updated: February 25, 2016
· rhysr

Angular e2e Testing Setup

Quick setup guide for end to end (e2e) testing of angularjs apps using karma, phantomjs and jasmine

Code is available in this github repo

This guide assumes you have gone through this guide

Create our directory for e2e tests or scenarios

mkdir test/e2e


Then we need to create our karma config

karma init configs/karma-e2e.conf.js

and answer the questions

  • framework: jasmine
  • require.js: no
  • Browser: PhantomJs (cycle through options with tab)
  • files: test/e2e/*.js
  • exclude: leave empty
  • karma watch: yes

we'll then need to edit the config file


Replace jasmine with angular




karma web server

We need to tell karma where our app is running so it can run it's test against it. For this we set up a proxy, from the karma web server to our app. Go to http://localhost:9876/ and you should see your app.

proxies = {
    "/": "http://localhost:3000"

Next, we need to be able to access karma's web interface, where we can register additional browsers for testing, or access the test debug mode. So, we'll need a path that karma can be served on using it's built in webserver.
It's important that you don't use a path that could possibly conflict with any path on your app or it won't get served.

urlRoot = "/__karma/";

Test Server

Next, we need to start up the karma server to run tests as the code is modified

karma start configs/karma-e2e.conf.js

Add Tests


describe('index page', function() {
    beforeEach(function() {

    it ('redirect works', function() {

    it ('has directive greeting', function() {

    it ('has partial greeting', function() {

    it ('has model greeting', function() {

If you check the terminal where the test runner is running, you will see that it has found the scenarios.js, executed all 4 tests and if all has gone well, passed successfully.

2 Responses
Add your response

When was this tutorial published?

over 1 year ago ·

I think this is older. It looks, from the use of browser().navigateTo, like it uses ngScenario, which I think is replaced by protractor.

over 1 year ago ·