3

I am used to WebDriver Java approach for implementing Page Object pattern, which is described here So everything in Java WebDriver Page Object pattern boils down to following:

  1. The public methods represent the services that the page offers
  2. Try not to expose the internals of the page
  3. Generally don't make assertions
  4. Methods return other PageObjects
  5. Need not represent an entire page
  6. Different results for the same action are modelled as different methods

So I am concerned about point 4.Methods return other PageObjects - Can it be applied to webdriverJS or Protractor cases?

The reason I am asking this is that I have not yet seen this approach applied to Protractor scripts - usually all specs(tests in jasmine) are intended for testing only ONE page, BUT not testing complete work flow (1.logging in 2.going into the system further to test a whole feature of a system, but not only one page) E.g.:

MainPage=require('./MainPage.js');
var LoginPage = function() {
    this.userNameInput = element(by.id('login'));
    this.passwordInput = element(by.id('password'));
    this.submitButton = element(by.id('submit'));

    this.loginWithValidCredentials= function(userName, password) {
        this.userNameInput.sendKeys(userName);
        this.passwordInput.sendKeys(password);
        this.submitButton.click();
        return new MainPage();
    };

    this.loginWithInvalidCredentials = function(userName, password) {
        this.userNameInput.sendKeys(userName);
        this.passwordInput.sendKeys(password);
        this.submitButton.click();
        return this;
    };
};
module.exports = LoginPage;
  1. Successful Login in to a page from LoginPage object: loginWithValidCredentials() function should return new MenuPage object
  2. Unsuccessful Login in to a page from LoginPage object: loginWithInvalidCredentials() function should return the same LoginPage object (e.g. this)

So basically I want to use this Page Object pattern in spec files like this:

var LoginPage = require('../pages/LoginPage.js');
describe('Login with username and password', function () {
    var loginPage = new LoginPage();
    var mainPage; 
  it('Logging in with VALID credentials', function () {               
  mainPage = loginPage.loginWithValidCredentials(
                    "username",
                    "password");
 **//interaction with mainPage goes here**
});

0 Answers0