October 2018
Intermediate to advanced
590 pages
15h 5m
English
To use Page Objects, we will need to create a separate JS file for each page. We need to specify the folder that contains these page files in the configuration file. The following is the change we make to nightwatch.conf.js:
module.exports = { ... page_objects_path: 'tests/e2e/page-objects', ...}
The following is the Page Object for the login page, tests/e2e/page-objects/LoginPage.js:
module.exports = { url: function () { return this.api.launchUrl + '/login' }, elements: { app: '#app', logoImage: 'img.logo', usernameInput: '#username', passwordInput: '#password', submitButton: 'button[type=submit]', formError: '.failed' }, commands: [{ login: function (username, password) { this .setValue('@usernameInput', username) .setValue('@passwordInput', ...Read now
Unlock full access