Overview

To create a page object simply create an object with properties that describe the page. Each page object should be located in a separate file.

Configure page objects location

Nightwatch reads the page objects from the folder (or folders) specified in the page_objects_path configuration property, e.g.:

nightwatch.json
{
  "page_objects_path": ["nightwatch/pages"]
}

The page_objects_path property can also be an array of folders, allowing you thus to logically split the page objects into smaller groups.

Set the .url property

You can optionally add a url property that designates the page's URL. To navigate to the page, you can call the navigate method on the page object.

The URL will usually be defined as a string:

nightwatch/pages/examplePage.js
module.exports = {
  url: 'https://google.com',
  elements: {}
};

It can also be a function in case the URL is dynamic. One use case for this is to support different test environments. You can create a function that gets called in the context of the page, thus allowing you to do:

nightwatch/pages/examplePage.js
module.exports = {
  url: function() { 
    return this.api.launchUrl + '/login'; 
  },
  elements: {}
};