Slack Reporter
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-devStep 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 :
- Navigate to url and click on Create your Slack app button :  
- Click on From Scratch after clicking on the Create New App button.  
- Give the app a suitable name, select a Slack workspace, and then hit the Create App button.  - Note : In this step, you may encounter following error which can only be resolved by Slack admins.  
- Now select Incoming Webhooks  
- Toggle to ON the activate Incoming webhook button  
- And then click on Add New Webhook to Workspace  
- Select a channel and click on Allow button to authorize it  
- That’s it, your webhook url is 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.
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
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 chromeStep 2: View the reports on Slack
