Overview

Slack Integration allows you to see your Nightwatch.js test results directly in your teams' Slack channels.

Configuration

Step 1: Install Nightwatch-Slack-Reporter

Install nightwatch-slack-reporter as a dependency in your nightwatch project.

npm i nightwatch-slack-reporter --save-dev

Step 2: Slack app setup

In order to integrate nightwatch-slack-reporter with Slack, you are required to set up an incoming webhook to send messages. Once you create the app on Slack, you will get a slack_webhook_url to interact with Slack. For more info you can refer to Slack webhook guide.

You must follow the steps to setup the app :

  1. Navigate to url and click on Create your Slack app button :

    create-slack-app

  2. Click on From Scratch after clicking on the Create New App button. create-app-from-scratch

  3. Give the app a suitable name, select a Slack workspace, and then hit the Create App button.

    slack-app-form

    Note : In this step, you may encounter following error which can only be resolved by Slack admins.

    approval-error

  4. Now select Incoming Webhooks

    select-incoming-webhook-feature

  5. Toggle to ON the activate Incoming webhook button

    toggle-to-on

  6. And then click on Add New Webhook to Workspace

    add-new-webhook

  7. Select a channel and click on Allow button to authorize it

    allow-to-authorize

  8. That’s it, your webhook url is ready to use

    webhook-ready-to-use

Step 3. Reporter integration with Nightwatch

nightwatch-slack-reporter requires an option object which will contain slack_message and slack_webhook_url. You can configure slack_message accordingly either as a function or message and also to set the value of slack_webhook_url which you made in step 2

via globals.js file

Make sure your globals.js is configured already; if not, please follow the setup guide.

globals.js
const options = {
   // function or message string
   slack_message: function(results, options) {
     // Message payload or string  
     return {
       text: 'Test completed, passed ' + results.passed + ', failed ' + results.failed,
       username: 'Nightwatch',
       icon_emoji: ':ghost:'
     }
   },
   // This can be specified with SLACK_WEBHOOK_URL environment variable
   slack_webhook_url: 'https://hooks.slack.com/services/...'
}
module.exports = {
  reporter: (require('nightwatch-slack-reporter')(options))
}
via configuration file
nightwatch.conf.js
const options = {
   slack_message: function(results, options) {
   return {
       text: 'Test completed, passed ' + results.passed + ', failed ' + results.failed,
       username: 'Nightwatch',
       icon_emoji: ':ghost:'
       }
   },
   slack_webhook_url: 'https://hooks.slack.com/services/...'
}
module.exports = {
   src_folders: ['tests'],
   globals: {
      reporter: (require('nightwatch-slack-reporter')(options)),
    },
   // Other stuff
}

Example

Step 0: Install Nightwatch

Follow the guide or watch the video to install Nightwatch from scratch.

Step 1: Run an example test

Consider the duckDuckGo.js example test :

describe('duckduckgo example', function() {
  it('Search Nightwatch.js and check results', function(browser) {
    browser
      .navigateTo('https://duckduckgo.com')
      .waitForElementVisible('#search_form_input_homepage')
      .sendKeys('#search_form_input_homepage', ['Nightwatch.js'])
      .click('#search_button_homepage')
      .assert.visible('.results--main')
      .assert.textContains('.results--main', 'Nightwatch.js');
  }); 
});

You don't need to do anything extra because you've configured the Slack reporter to be global. Run the tests as usual :

npx nightwatch examples/tests/duckDuckGo.js --env chrome

Step 2: View the reports on Slack

reports