Exploring the implementation of a simple test using the page objects pattern, inspired by the guidelines in 'docs/page-objects'.
Two files were created - one describing the page object and the other utilizing this page object to conduct a test on a specific page.
//page object
var LoginPage = function() {
this.userInput = browser.driver.findElement(by.id('username'));
this.pwdInput = browser.driver.findElement(by.id('password'));
this.btnEnter = browser.driver.findElement(by.id('btnLogin'));
this.get = function(){
browser.get('http://example.com');
};
this.setUser = function (user){
this.userInput.sendKeys(user);
};
this.setPasswd = function (password) {
this.pwdInput.sendKeys(password);
};
this.clickBtnEnter = function (){
btnEnter.click();
};};
The spec file:
var loginPage = require('./LoginPage.js');
describe('myApp', function() {
it('should save contract config', function (){
loginPage.get();
loginPage.setUser('userid');
loginPage.setPasswd('passwd');
loginPage.clickBtnEnter();
});
});
An error message stating TypeError: Object # has no method 'get' appears when attempting to run the test code at the line: loginPage.get();.
Different solutions for implementing page objects in Protractor are available, such as Astrolable. This variety has brought some uncertainty regarding the correct usage of page objects.
If you have any suggestions on how to resolve this issue with the test, your help would be greatly appreciated.
Thank you for your assistance.