Using the Page Object test pattern
Creating and maintaining a test suite for an application is a considerable amount of overhead, and a prudent developer will mold a test suite such that the normal evolution of a software application will not force developers to spend an unduly long amount of time to maintain the test code.
A surprisingly sensible design pattern called the Page Object pattern encapsulates segments of the page-specific user experience and abstracts it away from the logic of the actual tests.
How to do it…
The test/e2e/signup_flow_test.js file presented in the Writing basic E2E tests recipe can be refactored into the following files using the Page Object pattern.
The test/pages/main.js file can be refactored as follows:
(test/pages/main.js)
var MainPage = function () {
// direct the browser when the page object is initialized
browser.get('/');
};
MainPage.prototype = Object.create({},
{
// getter for element in page
signupLink: {
get: function() {
...