0

I have an AngularJS app. I would like to implement some end-to-end testing that I can run on-demand. In an effort to do this, I've built a basic test screen with the following:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Results</title>

    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine-html.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/boot.js"></script>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular-mocks.js"></script>

    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.css" />

    <!-- Load the Test Files-->
    <script type="text/javascript" src="e2e/tests.e2e.js"></script>
</head>
<body>
    <a href="#" onclick="env.execute()">run tests</a>

</body>
</html>

My tests.e2e.js file looks like the following:

'use strict';

describe('MyApp', function() {
    browser.get('http://localhost:11000/index.html');

    describe('Welcome Screen', function () {
    });
});

When click "run tests" in my test runner, I get an error that says:

MyApp encountered a declaration exception
ReferenceError: browser is not defined

My question is, what am I doing wrong? The examples I've seen use browser to basically start the app. However, I can't seem to figure out how to do end-to-end tests on-demand.

Thank you for any help you can provide.

user3284007
  • 1,697
  • 7
  • 27
  • 43
  • possible duplicate of [Where does the browser() object is defined in angluarJS ?](http://stackoverflow.com/questions/13754336/where-does-the-browser-object-is-defined-in-angluarjs) – Conqueror Mar 28 '14 at 00:47
  • even after including angular-scenario.js, I still get the "browser is not defined" error. – user3284007 Mar 28 '14 at 01:25
  • Whats your test runner? – andrbmgi Mar 28 '14 at 03:38
  • All of my code is posted in this question. I do not have protractor or karma setup as I thought those were more for automated testing. I want to run my tests on-demand, which is why I created the web page shown in the first code snippt. – user3284007 Mar 28 '14 at 11:47

1 Answers1

0
(function (module) {

    var myController = function ($scope, $http) {

        $http.get("/api/myData")
            .then(function (result) {
                $scope.data= result.data;
            });
    };

    module.controller("MyController",
        ["$scope", "$http", myController]);

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



describe("myApp", function () {

    beforeEach(module('myApp'));

    describe("MyController", function () {

        var scope, httpBackend;
        beforeEach(inject(function ($rootScope, $controller, $httpBackend, $http) {
            scope = $rootScope.$new();
            httpBackend = $httpBackend;
            httpBackend.when("GET", "/api/myData").respond([{}, {}, {}]);
            $controller('MyController', {
                $scope: scope,
                $http: $http
            });
        }));

        it("should have 3 row", function () {
            httpBackend.flush();
            expect(scope.data.length).toBe(3);
        });
    });
});
sadeghhp
  • 621
  • 14
  • 28