Can I create reusable test steps in nightwatch.js? Can I create reusable test steps in nightwatch.js? selenium selenium

Can I create reusable test steps in nightwatch.js?


You can create custom commands for that: http://nightwatchjs.org/guide#writing-custom-commands

  1. in nightwatch.json specify the path to the folder that will contain your custom command file
  2. create a js file and name it how your custom command should be names (ie login.js)
  3. write the code you need:

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;};