Automated Test Results to Your Slack
A Java library to send automated test results as a notification to slack. All you need is to add this library as a dependency in your project.
Features
- Supports Web, Mobile and API test automation
- Supports TestNG framework (Cucumber is in progress)
- Provides fail/pass info on suite, test, class and method level
- Notifies if a test is retried - pass or fail
- Provides test duration info on suite and test level
- Provides branch details where the tests are executed
Prerequisites
- Slack webhook URL - see this link on how to get one
- TestNG v7.0.0 and above
Maven Dependency:
<dependency>
<groupId>io.github.automationreddy</groupId>
<artifactId>java-slack-notify</artifactId>
<version>1.1.0</version>
</dependency>
Gradle
implementation group: 'io.github.automationreddy', name: 'java-slack-notify', version: '1.1.0'
Usage
- Create
slack.propertiesfile and keep in yoursrc/main/resourcesfolder - Add the following keys and values to it
WEBHOOK_URL=<Webhook URL>andNOTIFY_ONLY_ON_FAILURE=true or false - If you want to include the branch name where your tests are executed, you can do so by adding BRANCH_NAME and BRANCH_LINK as runtime variables. Make sure to add both variables
html //If you are using maven, pass the arguments as below: -DBRANCH_NAME=test-branch -DBRANCH_LINK=https://github.com - Add the
TestNGSlackReporterlistener either to the test class or in thetestng.xmlfile (Cucumber support is in progress)
Adding listener at class level
@Listeners(TestNGSlackReporter.class)
public class TestClass {
//ToDo
}
Adding listener in testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Regression">
<listeners>
<listener class-name="io.github.automationreddy.testng.TestNGSlackReporter"/>
</listeners>
</suite>
How it works
After the test execution is done, reporter will build the message and send notification based on the user input and test pass/fail status
Options
WEBHOOK_URL
Slack webhook url
Type: String
Optional: NO
Default: NA
NOTIFY_ONLY_ON_FAILURE
Based on this option, notification will be sent. If this is true, notification will only be sent when the test is failed. Otherwise, it sends irrespective of the test status
Type: String
Optional: YES
Default: false
Screenshot

Limitations
TestNG
- It doesn't support the versions older than v7.0.0
- It doesn't support multiple suite files as below
xml <suite name="allSuites"> <suite-files> <suite-file path="suite1.xml" /> <suite-file path="suite2.xml" /> ... </suite-files> </suite>