I am looking to create reusable components within my nightwatch.js
tests.
ie. login to the web app, logout of the web app
What is the best method / pattern for creating these steps in a reusable way?
I am looking to create reusable components within my nightwatch.js
tests.
ie. login to the web app, logout of the web app
What is the best method / pattern for creating these steps in a reusable way?
You can create custom commands for that: http://nightwatchjs.org/guide#writing-custom-commands
exports.command = function(username, password) {
this
.waitForElementVisible('#password', 4000)
.setValue('#password', password)
.waitForElementVisible('#username', 1000)
.setValue('#username', username)
.waitForElementVisible('#sign_in', 1000)
.click('#sign_in')
.waitForElementVisible('h1.folder-title', 10000)
return this;
};
.login("your_username", "your_password")
This is typically done with page objects. http://nightwatchjs.org/guide#page-objects
Then you can just
var myPage = client.page.myPage();
myPage.navigate()
.assert.title('MyPage')
.login('foo', 'bar)
.assert.displayName('foo');
To add to the previous answer, you can also create custom assertions and reporters in addition to commands.
The Nightwatch Guide has more information on customization and extending Nightwatch.