Created
March 12, 2015 16:25
-
-
Save s-stude/343a637364b215b2ad03 to your computer and use it in GitHub Desktop.
Angular (manual bootstrap) + Protractor Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.config = { | |
seleniumAddress: 'http://localhost:4444/wd/hub', | |
specs: ['todo-spec.js'] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<body> | |
<div ng-controller="MyController"> | |
Hello {{greetMe}}! | |
<ul ng-repeat="item in items"> | |
<li>{{ item }}</li> | |
</ul> | |
<input type="text" ng-model="newItem"/> | |
<button class="button" ng-click="add()">Add</button> | |
<h3>Repos</h3> | |
<ul ng-repeat="repo in repos"> | |
<li> {{ repo.full_name }}</li> | |
</ul> | |
<button class="btn-load-repos" ng-click="loadRepos()">Load repos</button> | |
</div> | |
<script src="http://code.angularjs.org/snapshot/angular.js"></script> | |
<script> | |
angular.module('myApp', []) | |
.controller('MyController', ['$scope', '$http', function ($scope, $http) { | |
$scope.greetMe = 'World'; | |
$scope.newItem = undefined; | |
$scope.items = [1, 2, 3]; | |
$scope.repos = []; | |
$scope.loadRepos = function () { | |
$http.get('https://api.github.com/repositories') | |
.then(function (repos) { | |
$scope.repos = repos.data; | |
}); | |
}; | |
$scope.add = function () { | |
$scope.items.push($scope.newItem); | |
} | |
}]); | |
angular.element(document).ready(function () { | |
angular.bootstrap(document, ['myApp']); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('test', function () { | |
it('should', function () { | |
browser.get('http://localhost:63342/protractor-demo/index.html'); | |
element(by.model('newItem')).sendKeys('abc'); | |
element(by.css('.button')).click(); | |
var items = element.all(by.repeater('item in items')); | |
expect(items.count()).toEqual(4); | |
expect(items.get(3).getText()).toEqual('abc'); | |
}); | |
it('should load repos', function () { | |
browser.get('http://localhost:63342/protractor-demo/index.html'); | |
element(by.css('.btn-load-repos')).click(); | |
var items = element.all(by.repeater('repo in repos')); | |
expect(items.count()).toEqual(100); | |
expect(items.get(2).getText()).toEqual('rubinius/rubinius'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment