JIRA_Integration

Reading Time: <15 minutes

What’s up Guys! Welcome to automationcalling.com

In real world, I see most of people are using third party reporting library for open automation framework, In fact I still do, for eg. Extent Report, Allure, TestNG or customized html report. I have been thinking how about avoiding third party library instead integrating test results to Defect Management/Test Management Tool. Is it possible? Yes Why not? :-).

This blog I’m going to explain 2 approaches regarding how efficiently we can use JIRA for your automation test. To proceed further, we should have the following setup in place.

Pre-requisites:

  • JIRA
    • Good to have Admin Access or at least necessary access
  • Test Automation Framework

Getting Started:

JIRA

To play with JIRA, probably two options, One is your company JIRA Server or you can use  your Own JIRA Server which can be found here https://atlassian.com/software/jira/download. JIRA offers 30 days trial license where you can play and get comfortable with Project Creation, Status, Roles and permission etc.,

The Installation is pretty simple steps, I’m going to explain for Windows :-).

  • Download JIRA from above link
  • Click Next till end and Finish
  • Once Done, It launch in browser to create user account
  • You can use your google account or use Atlassian account
  • There you go, your account creation is success and load login page.
  • Create a New Project, what I did is, I use existing Sample Project
  • Congratulations! all set and you are good to go :-).

Test Automation Framework

In case if you don’t have such framework, feel free to clone and play with the framework https://github.com/automationcalling/AutomationIntegrationToJira

Technical Requirement:

To Integrate either Automation results or opening bugs programatically to Jira, You need Rest API Support in framework and Jira Util which can be downloaded from the above link.

JIRA Util:

Jira Rest API support cookies based authentication. We can get Session ID from response which can be passed to other resource endpoint.

Create Session:

public String returnSessionID() {
    return restAssuredCore.setURLEncodingStatus(false)
            .setContentType("application/json")
            .setBody(PAYLOADPATH + "Credential.json")
            .invokeRestCall("POST", "/auth/1/session").getJsonPathReturnValue("str", "session.value");
}

Create Bug using JIRA Rest API Programatically

Note: The below one is easy and simple example. The other option is, you can keep json file and update data dynamically and load the file.

public String createBug(String... jiraValues) {
    return restAssuredCore.setURLEncodingStatus(false)
            .setContentType("application/json")
            .setHeader("Cookie", "JSESSIONID=" + returnSessionID())
            .setBodyasString("{\n" +
                    "    \"fields\": {\n" +
                    "       \"project\":\n" +
                    "       { \n" +
                    "          \"key\": \"" + jiraValues[0] + "\"\n" +
                    "       },\n" +
                    "       \"summary\": \"" + jiraValues[1] + "\",\n" +
                    "       \"description\": \"" + jiraValues[2] + "\",\n" +
                    "       \"issuetype\": {\n" +
                    "          \"name\": \"Bug\"\n" +
                    "       }\n" +
                    "   }\n" +
                    "}")
            .invokeRestCall("POST", "/api/2/issue").getJsonPathReturnValue("in", "id");
}

Approach 1:

Automatic Bug creation to JIRA based on Failures

This approach will help you to create a bug in JIRA system when your automation tests get failed. Please refer the below video for further explanation.

 

Note: One drawback of this approach is, it’s possible to create unwanted bugs to JIRA System related to DOM Changes or some other issue, the bugs it creates may not be always functional bugs. This kind of issue still can be controlled your automation code, however probability is high in terms of creating unwanted bugs.

Approach 2:

I strongly believe this approach works very well but it’s my opinion. In order to avoid unnecessary bug creation programatically as well as avoid including third party report library, We need to create dedicated Automation Agile Project. All your backlog automation need to be created Stories, test cases must be mapped to Sub Tasks.

  • Backlog Stories -> Automation Stories
  • Test Cases of Stories-> Individual Sub Tasks of Automation Stories.

Simple Workflow:

workflow

Please note, we should have stable JIRA workflow to achieve Done->Reopen Status which indicates failure of your automation test cases.

Please take a look on below video for further explanation:

For Automation perspective, we need to concentrate on task level to make sure all test cases are passed in your automation test results.

Here is the final report we can archive or create in the JIRA Dashboard:

I filtered out automation task in JIRA dashboard which display results based on last automation run.

Automated_Report_in JIRA

Drawbacks:

I don’t see any drawbacks in this approach, may be the same task keep Reopen and Done. That’s it :-).

Conclusion:

I strongly believe this approach we can easily track automation results in daily basis especially CI/CD integration as well as release testing. The idea is not to use third party library rather we can integrate our automation results in JIRA which can be viewed by anyone in project team to track daily results.

Happy Automation!

Please subscribe my blogs automationcalling.com for more updates!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s