Skip to content

A Java library to send automated test results to a slack channel

License

Notifications You must be signed in to change notification settings

AutomationReddy/java-slack-notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Example project is here

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.2.0</version>
</dependency>

Gradle

implementation group: 'io.github.automationreddy', name: 'java-slack-notify', version: '1.2.0'

Usage

  1. Create slack.properties file and keep in your src/main/resources folder
  2. Add the following keys and values to it WEBHOOK_URL=<Webhook URL>, NOTIFY_ONLY_ON_FAILURE=true or false and SHOW_FAILED_RESULTS_ONLY=true or false
  3. 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
Example:
//If you are using maven, pass the arguments as below:
-DBRANCH_NAME=test-branch -DBRANCH_LINK=https://github.com
  1. Add the TestNGSlackReporter listener either to the test class or in the testng.xml file (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: Boolean
Optional: YES
Default: false

SHOW_FAILED_RESULTS_ONLY

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

Screenshot

Slack Notification

Only Failed Tests

Limitations

TestNG

  • 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>

About

A Java library to send automated test results to a slack channel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages