Book Image

Learning Behavior-driven development with Javascript

Book Image

Learning Behavior-driven development with Javascript

Overview of this book

Table of Contents (17 chapters)
Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

A page object for a rich UI


It is now time to change our UI tests to use the Page Object pattern. The first thing is to create an initial page object that represents the browser. This will encapsulate all the logic about navigation and executing scripts. This way, we can, in the future, replace WebDriver with another tool, if it is necessary. Let's create such an object inside the test/support/ui.js file:

'use strict';

module.exports = function (port, driver) {
  function uriFor(uiName) {
    return 'http://localhost:' + port + '/test/' + uiName + '.html';
  }

  return {
    uriFor: uriFor,
    goTo: function (uiName) {
      return driver.get(uriFor(uiName));
    },
    executeScript: driver.executeScript.bind(driver),
    executeAsyncScript: driver.executeAsyncScript.bind(driver)
  };
};

The module is very simple; it just exposes a constructor for our main page object. The uriFor method is almost identical to the one we had before in test/index.js, and it will construct the right URI for...