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.
- 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
Example project is here
- Slack webhook URL - see this link on how to get one
- TestNG v7.0.0 and above
<dependency>
<groupId>io.github.automationreddy</groupId>
<artifactId>java-slack-notify</artifactId>
<version>1.2.0</version>
</dependency>
implementation group: 'io.github.automationreddy', name: 'java-slack-notify', version: '1.2.0'
- Create
slack.properties
file and keep in yoursrc/main/resources
folder - Add the following keys and values to it
WEBHOOK_URL=<Webhook URL>
,NOTIFY_ONLY_ON_FAILURE=true or false
andSHOW_FAILED_RESULTS_ONLY=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 or environment variables. Make sure to add both variables
//If you are using maven, pass the arguments as below:
-DBRANCH_NAME=test-branch -DBRANCH_LINK=https://github.com
- Add the
TestNGSlackReporter
listener either to the test class or in thetestng.xml
file (Cucumber support is in progress)
@Listeners(TestNGSlackReporter.class)
public class TestClass {
//ToDo
}
<?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>
After the test execution is done, reporter will build the message and send notification based on the user input and test pass/fail status
Slack webhook url
Type: String
Optional: NO
Default: NA
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: Boolean
Optional: YES
Default: false
If you want to receive only the failed results and ignore the passed, set this to true. Otherwise, all results will be included in the message
Type: Boolean
Optional: YES
Default: false
- It doesn't support the versions older than v7.0.0
- It doesn't support multiple suite files as below
<suite name="allSuites">
<suite-files>
<suite-file path="suite1.xml" />
<suite-file path="suite2.xml" />
...
</suite-files>
</suite>