1
votes

I am trying to set up unit/e2e tests for the angular app. Following the instructions on the protractor web site and numerous other samples I have set it up and being able to run tests unless they are referring to the angular objects. Here is the sample html page I want to have tests for:

<!DOCTYPE html>
<html ng-app="app">
<head>
    <script type="text/javascript" src="libraries/angular.js"></script>
    <script type="text/javascript" src="libraries/angular-route.js"></script>
    <script type="text/javascript" src="libraries/angular-touch.js"></script>
    <script type="text/javascript" src="libraries/angular-sanitize.js"></script>
    <script type="text/javascript" src="libraries/angular-mocks.js"></script>

    .....
</head>
<body ng-controller="DefaultController">

...

The test:

describe('Logon page', function ()
{
    beforeEach(function ()
    {
        browser.get('default.html');

        angular.module("app");
    });

    it('should have a title', function ()
    {
        expect(browser.getTitle()).toEqual('Logon');
    });
});

as soon as I run it I got an exception: "ReferenceEror: angular is not defined". If I remove line "angular.module("app");" - it works fine. By looking at console output of the protractor it looks like Protractor.waitForAngular() is internally called after I try to access "angular" object. But as far as I understand browser.get - should load it before?

I use angular 1.3.4 and protractor 1.4.0.

Thanks in advance.

1

1 Answers

1
votes

Why do you need the angular.module("app"); part? The code you write in a Protractor test does not run in the browser. It uses the browser API (through Selenium) but you don't have direct access to angular modules or other structures on the page you're testing.

I think you may have mixed up the concepts of unit tests and E2E tests. You'll need angular.module("app"); just for unit tests.