This is my current approach to the page object model. It's a simple setup.
var loginPage = require('../pages/loginPage');
var homePage = require('../pages/homePage');
describe('Login', function () {
it('A successful login should lead to the home page with the correct title.', function () {
browser.driver.get("https://dev.mysite.com/");
loginPage.login('TestUser', 'TestPassword');
homePage.getHeaderText();
//expect header text to equal "My header"
});
});
In the Protractor Style Guide, they recommend a different method like this one. It involves creating an object for each page unique to every test. Is there any benefit to following this pattern?
var loginPage = require('../pages/loginPage');
var homePage = require('../pages/homePage');
describe('Login', function () {
var loginPageObj = new loginPage();
var homePageObj = new homePage();
it('A successful login should lead to the home page with the correct title.', function () {
browser.driver.get("https://dev.mysite.com/");
loginPageObj.login('TestUser', 'TestPassword');
//or should homePageObj be initialized here,
//right before it is first used?
homePageObj.getHeaderText();
//expect header text to equal "My header"
});
});