A simple perform command which allows access to the Nightwatch API in a callback. Can be useful if you want to read variables set by other commands.

The callback signature can have up to two parameters.

  • no parameters: callback runs and perform completes immediately at the end of the execution of the callback.
  • one parameter: allows for asynchronous execution within the callback providing a done callback function for completion as the first argument.
  • two parameters: allows for asynchronous execution with the Nightwatch api object passed in as the first argument, followed by the done callback.

In the case of asynchronous execution, the timeout can be controlled by setting the asyncHookTimeout global. See Using test globals for more info.

Parameters

Name Type description
callback function

The function to run as part of the queue.

Usage

this.demoTest = function (browser) {
  var elementValue;
  browser
    .getValue('.some-element', function(result) {
      elementValue = result.value;
    })
    // other stuff going on ...
    //
    // self-completing callback
    .perform(function() {
      console.log('elementValue', elementValue);
      // without any defined parameters, perform
      // completes immediately (synchronously)
    })
    //
    // asynchronous completion
    .perform(function(done) {
      console.log('elementValue', elementValue);
      // potentially other async stuff going on
      // on finished, call the done callback
      done();
    })
    //
    // asynchronous completion including api (client)
    .perform(function(client, done) {
      console.log('elementValue', elementValue);
      // similar to before, but now with client
      // potentially other async stuff going on
      // on finished, call the done callback
      done();
    });
};