Skip to content

Instantly share code, notes, and snippets.

@s-stude
Created March 12, 2015 16:25
Show Gist options
  • Save s-stude/343a637364b215b2ad03 to your computer and use it in GitHub Desktop.
Save s-stude/343a637364b215b2ad03 to your computer and use it in GitHub Desktop.
Angular (manual bootstrap) + Protractor Tests
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};
<!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>
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