Site icon Vinsguru

JMeter – How To Share Performance Test Results in Slack

Overview:

Test automation is not just automating the application. I would say even sharing the test results programmatically with the team is part of Test automation. So that , team does not depend on any individual to get the results. Team can also take further action based on the test results without any delay.

In this article, we are going to see how we can share our performance test results in Slack.

Slack comes with many Apps & APIs for easy integration with other applications. Check here for more information.

 

Slack – Jenkins CI App – Integration:

I assume most of us use Jenkins for the Continuous automated testing. So in this article, I have provided the steps to integrate Jenkins and Slack. If you use other tools like Team City, Bamboo etc, the process will still be almost same.

Slack:

 

Jenkins:

 

Jenkins – Performance Test Job:

 

Sharing Results using Slack HTTP API:

The above Jenkins plugin is very easy to use. However it does not allow us to upload files / share images etc. Lets see How it can be done using Slack HTTP API.

{
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "pretext": "Optional text that appears above the attachment block",
            "image_url": "http://my-website.com/path/to/image.jpg"
        }
    ]
}

Note: Please ensure that link for your image is available in public. You might not be able to use this approach to share if images are within the private network. In this case, you need to upload them to a site – like Amazon S3 – then use public URL of the site before sharing via Slack.

Slack – File Upload:

When your images are not available in public, Slack provides a file upload API to upload images & other files.

curl -F file=@BytesThroughputOverTime.png -F channels=#perf-test -F token=my-token https://slack.com/api/files.upload
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.HttpClientBuilder;

public class SlackUtil {

    public static void main(String[] args) throws ClientProtocolException, IOException {

        String url = "https://slack.com/api/files.upload?token=mytoken&channels=mychannel";
        String filePath = "BytesThroughputOverTime.png";


        HttpClient client = HttpClientBuilder.create().build();
        HttpPost post = new HttpPost(url);

        HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", new FileBody(new File(filePath))).build();
        post.setEntity(reqEntity);

        HttpResponse response = client.execute(post);

        //check the response
        System.out.println("Response Code : " +
            response.getStatusLine().getStatusCode());

        BufferedReader rd = new BufferedReader(
            new InputStreamReader(response.getEntity().getContent()));

        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }

        System.out.println(result.toString());
    }

}

 

Summary:

As part of Continuous Performance Testing process we run the performance test using Jenkins periodically. Only you, as a performance test engineer, mostly know the results. Other team member might not be aware of performance test results. Using JMeter command line tool, we can create beautiful charts and using Slack API we can share the results programmatically.

 

Happy Testing & Subscribe 🙂

 

Share This:

Exit mobile version