Last active
November 30, 2016 10:46
-
-
Save rahulmr/8f7f45b397ff593435c71b2ed0ce0111 to your computer and use it in GitHub Desktop.
Protractor example suite using page objects
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
'use strict'; | |
var AngularPage = function () { | |
browser.get('http://www.angularjs.org'); | |
}; | |
AngularPage.prototype = Object.create({}, { | |
todoText: { get: function () { return element(by.model('todoList.todoText')); }}, | |
addButton: { get: function () { return element(by.css('[value="add"]')); }}, | |
yourName: { get: function () { return element(by.model('yourName')); }}, | |
greeting: { get: function () { return element(by.binding('yourName')).getText(); }}, | |
todoList: { get: function () { return element.all(by.repeater('todo in todoList.todos')); }}, | |
typeName: { value: function (keys) { return this.yourName.sendKeys(keys); }} , | |
todoAt: { value: function (idx) { return this.todoList.get(idx).getText(); }}, | |
addTodo: { value: function (todo) { | |
this.todoText.sendKeys(todo); | |
this.addButton.click(); | |
}} | |
}); | |
module.exports = AngularPage; |
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
'use strict'; | |
var AngularPage = require('../pages/angular.page.js'); | |
describe('angularjs homepage', function () { | |
var page; | |
beforeEach(function () { | |
page = new AngularPage(); | |
}); | |
it('should greet the named user', function () { | |
page.typeName('Julie'); | |
expect(page.greeting).toEqual('Hello Julie!'); | |
}); | |
describe('todo list', function () { | |
it('should list todos', function () { | |
expect(page.todoList.count()).toEqual(2); | |
expect(page.todoAt(1)).toEqual('build an angular app'); | |
}); | |
it('should add a todo', function () { | |
page.addTodo('write a protractor test'); | |
expect(page.todoList.count()).toEqual(3); | |
expect(page.todoAt(2)).toEqual('write a protractor test'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment