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.
For more information on testing visit: https://www.rapidvaluesolutions.com/software-testing/
2. Real-time Automation Result in Slack Channel
2
Step-by-step Approach to Achieve Real-time Automation Result in Slack Channel
1. Create an account in Slack and then create a Slack workspace. Use https://slack.com/get-started#/
2. Create a Slack application to communicate with your channel about the automation execution status.
Use https://api.slack.com/apps
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 https://api.slack.com/apps 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:
o file:write
o incoming:webhook
User Token Scopes:
o file:write
Two Slack utilities have been created to send real-time test results and the test execution reports to the Slack
channel. Following are the methods:
o sendTestExecutionStatusToSlack helps to send the test results to the Slack channel with the help of
the Webhook URL and channel name.
o 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_SLACK_CHANNEL_NAME";
private static String botUserOAuthAccessToken = " YOUR_BOT_USER_OAuth_TOKEN";
public void sendTestExecutionStatusToSlack(String message) throws Exception {
try {
StringBuilder messageBuider = new StringBuilder();
messageBuider.append(message);
Payload payload =
Payload.builder().channel(channelName).text(messageBuider.toString()).build();
WebhookResponse webhookResponse = Slack.getInstance().send(urlSlackWebHook,
payload);
3. Real-time Automation Result in Slack Channel
3
webhookResponse.getMessage();
} catch (IOException e) {
System.out.println("Unexpected Error! WebHook:" + urlSlackWebHook);
}
}
public void sendTestExecutionReportToSlack(String testReportPath) throws Exception {
String url = "https://slack.com/api/files.upload?token=" + botUserOAuthAccessToken +
"&channels=" + channelName + "";
try {
HttpClient httpclient = HttpClientBuilder.create().build();
HttpPost httppost = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
FileBody fileBody = new FileBody(new File(testReportPath));
builder.addPart("file", fileBody);
httppost.setEntity(builder.build());
HttpResponse response = null;
response = httpclient.execute(httppost);
HttpEntity result = response.getEntity();
System.out.println(result.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
You can use both the above 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.
4. Real-time Automation Result in Slack Channel
4
Sample Output: Slack View:
Try to use the above methods to send real-time test results to Slack channel and achieve your automation results.
Conclusion
jslack Java library is a robust library that helps to send real-time information via various Slack channels.
Nowadays, the usage of Slack has increased and in high demand for all areas of communication. In
automation, the jslack plays an important role to send real-time test execution status, complete results, and
report documents. This will helps the management level to evaluate the stability of the applications very
quickly. Slack integrations into the automation framework will play a critical role in the upcoming
automation world.
By
Sanoj S
Test Architect
5. Real-time Automation Result in Slack Channel
5
About RapidValue
RapidValue is a global leader in digital product engineering solutions including mobility, omni-
channel, IoT, AI, RPA and cloud to enterprises worldwide. RapidValue offers its digital services to
the world’s top brands, Fortune 1000 companies and innovative emerging start-ups. With offices in
the United States, the United Kingdom, Germany and India and operations spread across the
Middle-East, Europe and Canada, RapidValue delivers enterprise services and solutions across
various industry verticals.
Disclaimer:
This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part
of it may be used, circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the
intended recipient of this report, you are hereby notified that the use, circulation, quoting, or reproducing of
this report is strictly prohibited and may be unlawful.
www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com
+1 877.643.1850 contactus@rapidvaluesolutions.com