O'Reilly logo

Learning Behavior-driven Development with JavaScript by Enrique Amodeo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required