Real-time Automation Results in Slack Channel


     We know that Slack is a powerful communication tool that brings the team together, wherever you are. Slack offers channels to stay organized and focused on central spaces for conversations, files, tools, and people. Slack provides workspaces, applications, and various team collaboration options. Slack applications help to act as chatbots on various occasions.

     The major advantages of Slack include all team communication in one place, integration with various services, one to one and private groups, the ability to integrate various bots or apps to your slack channel depending on your needs.

    Nowadays, we know that most of the CI tools have the capability to integrate with slack to share real-time test execution results. In this article, I would like to share a couple of utilities written in Java that describe how to send realtime automation test results via slack channels. The automation results included both plain text results and the attached reports.


  • You must have a slack account.
  • Add the latest jslack dependency into pom.xml if you are using Maven.
  • Add the latest version of following dependencies to pom.xml to handle the API operations,
    • httpclient
    • httpmime  
  • Add extentreports dependency to pom.xml file to generate the HTML automation report.

Step-by-step procedure

  1. Create an account in Slack and then create a Slack workspace. Use
  2. Create a Slack application to communicate with your channel about the automation execution status. Use
  3. Create a Slack channel by clicking plus icon right to Channels in your slack workspace. Keep the Slack channel name in your mind and it useful during the scripting.
  4. Add created Slack application to your Slack channel by clicking Add an app link from the slack channel.
  5. Go to and select your Slack application. Select Incoming Webhooks and activate it. Scroll down the page and you will get Webhook URL for your channel. This Webhook URL is an important parameter in your script which helps to send the messages to your Slack channel.
  6. Go to OAuth & Permissions section, there you will get Bot User OAuth Access Token which helps the Slack application to send files into your Slack Channel. Copy the Bot User OAuth Access Token and you can use it in the script.
  7. Scroll down in OAuth & Permissions page to reach the Scopes section. Make sure that following scopes are added,
    • Bot Token Scopes:
      • file:write
      • incoming:webhook
    • User Token Scopes:
      • file:write

  I have created two Slack utilities to send real-time test results and the test execution reports to the Slack channel. Following are the methods:

  • sendTestExecutionStatusToSlack helps to send the test results to the Slack channel with the help of the Webhook URL and channel name.
  • sendTestExecutionReportToSlack helps to send the automation test execution report with the help of file upload API, Bot User OAuth Token, and channel name. Following are the detailed implementation of both methods,

private static String urlSlackWebHook = “YOUR_WEBHOOK_URL”;
private static String channelName = “YOUR_CHANNEL_NAME”;
private static String botUserOAuthAccessToken = “YOUR_BOT_USER_OAuth_TOKEN”;

public void sendTestExecutionStatusToSlack(String message) throws Exception {
try {
StringBuilder messageBuider = new StringBuilder();
Payload payload = Payload.builder().channel(channelName).text(messageBuider.toString()).build();

WebhookResponse webhookResponse = Slack.getInstance().send(urlSlackWebHook, payload);
} catch (IOException e) {
System.out.println(“Unexpected Error! WebHook:” + urlSlackWebHook);

public void sendTestExecutionReportToSlack(String testReportPath) throws Exception {
String url = “ “;
try {
HttpClient httpclient = HttpClientBuilder.create().disableContentCompression().build();
HttpPost httppost = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
FileBody fileBody = new FileBody(new File(testReportPath));
builder.addPart(“file”, fileBody);
builder.addTextBody(“channels”, channelName);
builder.addTextBody(“token”, botUserOAuthAccessToken);
HttpResponse response = null;
response = httpclient.execute(httppost);
HttpEntity result = response.getEntity();
} catch (Exception e) {

     You can use above both methods based on your convenience in the automation listener class. If you are using the TestNG framework then you can implement the ITestListener interface and use both methods inside the implemented methods of ITestListener to send real-time test execution results to your Slack channel.

Sample Output: Slack View

Slack Automation Flow

    Try to use the above methods to send real-time test results to Slack channel and enjoy your automation.

make it perfect!