2014-03-28 2 views
0

AngularJS 앱이 있습니다. 주문형으로 실행할 수있는 몇 가지 엔드 투 엔드 테스트를 구현하고 싶습니다. 이 작업을 수행하기위한 노력의 일환으로, 내가 가진 기본적인 테스트 화면을 구축 한 다음엔드 투 엔드 테스트 재스민 AngularJS 앱

'use strict'; 

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

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

때 클릭 "실행 테스트 :

<!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> 

내 tests.e2e.js 파일은 다음과 같습니다 "테스트 주자는 다음과 같은 오류 메시지가 표시됩니다.

MyApp encountered a declaration exception 
ReferenceError: browser is not defined 

내 질문은 무엇을 잘못 했습니까? 내가 본 예는 브라우저를 사용하여 기본적으로 앱을 시작합니다. 그러나 주문형 엔드 - 투 - 엔드 테스트를 수행하는 방법을 알아낼 수 없습니다.

제공 할 수있는 도움에 감사드립니다.

+0

가능 중복 [여기서 않는 브라우저() 객체가 정의되어 angluarJS? (http://stackoverflow.com/questions/13754336/where-does-the-browser-object- is-defined-in-angluarjs) – Conqueror

+0

angular-scenario.js를 포함한 후에도 "브라우저가 정의되지 않았습니다"라는 오류가 발생합니다. – user3284007

+0

테스트 주자는 무엇입니까? – andrbmgi

답변

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); 
     }); 
    }); 
}); 
+3

대답을 설명해 주시겠습니까? :) – glepretre

관련 문제