In this blog, we will explore how to update test execution results in JIRA-Zephyr squad using REST APIs in Java using Rest Assured.ย
Jira is a popular tool for managing software projects, and Zephyr is a plugin for Jira that helps teams manage their testing efforts. One of the key features of Zephyr is the ability to create and execute test cycles, which allow you to group related test cases and track their progress. In this blog, we’ll show you how to use the Jira REST API and Rest Assured to create a test cycle, add test cases, get the execution ID, and update the execution status.ย
Before we get started, you’ll need to have some prerequisites in place:ย
- A Jira account with permission to create test cycles and execute test cases.ย
- A Zephyr for Jira Cloudย
- Basic knowledge of Java and REST APIs.ย
Flow diagram to update the test execution result in Jira-Zephyr

ย ย ย ย ย ย ย ย ย ย ย ย
Before you can update test execution results in Jira-Zephyr using Rest APIs in Java using Rest Assured, you need to follow a few steps.ย
1. First, you must create test cases in Jira and add test steps using Zephyr. Then, you need to create versions/releases for that project. Once this is done, you must generate anโฏAtlassian API Token ( refer:https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/) and obtain theโฏZephyr Secret Key and Access Key(refer :https://support.smartbear.com/zephyr-squad-cloud/docs/api/api-keys.html).ย
2. Next, you need to interact with JIRA REST API’s and authenticate your requests. For this, you need to specify the Jira Base URL and get theโฏproject ID’sโฏusing the API-SEARCH-PROJECTS endpoint.
- JiraBaseURLโฏ= https://<Your-UserName>.atlassian.netย
- API-SEARCH-PROJECTSโฏ= https://<Your-UserName>.atlassian.net/rest/api/latest/projectย
3. Once you have the project ID, you can obtain theโฏversion ID’sโฏusing the API-SEARCH-VERSIONS endpoint. Additionally, you need to obtain theโฏIssue Keyโฏby hitting the API_SEARCH_ISSUES endpoint.ย
- ย API-SEARCH-VERSIONSโฏ= https://<Your-UserName>.atlassian.net/rest/api/latest/project/<projecctID>/version
- API_SEARCH_ISSUESโฏ=โฏhttps://prod-play.zephyr4jiracloud.com/connect/rest/api/2/searchย
Note: To retrieve the expected values, you can use Postman to hit the four APIs mentioned above.ย
- After you have all the necessary values, you can continue with the next steps. It is important to note that you mustโฏgenerate a JWT token for every Zephyr endpoint you are hitting. For more information on generating JWT tokens, refer toโฏhttps://support.smartbear.com/zephyr-squad-cloud/docs/api/jwt-token.html.ย
ย
Step 1: Create a Test Cycle in Jira-Zephyrย
To create a test cycle in Jira-Zephyr, you need to send a POST request to the Jira REST API. Here’s how you can do it in Java using Rest Assured:ย
- zephyrBaseUrl =โฏhttps://prod-play.zephyr4jiracloud.com/connectย
- createCycleEndpoint = /public/rest/api/1.0/cycle?expand=&clonedCycleId=ย
String cycleUri = zephyrBaseUrl + createCycleEndpoint;ย
Response createCycleResponse = given()ย
ย ย ย ย ย ย ย .header("zapiAccessKey", accessKey)ย
ย ย ย ย ย ย ย .header("zapiSecretKey", secretKey)ย
ย ย ย ย ย ย ย .header("Authorization", WrapperFunctions.getJWT(cycleUri, client))ย
ย ย ย ย ย ย ย .header("Content-Type", "application/json")ย
ย ย ย ย ย ย ย .body(CommonFunctions.getCycleCreationJsonPayload(cycleName,cycleDescription,startDate,projectId,versionId))ย
ย ย ย ย ย ย ย .post(cycleUri)ย
ย ย ย ย ย ย ย .then()ย
ย ย ย ย ย ย ย .statusCode(200)ย
ย ย ย ย ย ย ย .extract()ย
ย ย ย ย ย ย ย .response();ย
String cycleId = createCycleResponse.jsonPath().getString("id");ย
ย
Step 2: Add Test Cases to the Test Cycleย
Once you have created the test cycle, you can add test cases. Here is how you can do it in Java using Rest Assured:ย
- zephyrBaseUrl =โฏhttps://prod-play.zephyr4jiracloud.com/connectย
- addTestCaseEndpoint = /public/rest/api/1.0/executions/add/cycle/ย
String addTestsUri = zephyrBaseUrl + addTestCaseEndpoint + cycleId;ย
ย
Response addTestsResponse = given()ย
ย ย ย ย ย ย ย .header("zapiAccessKey", accessKey)ย
ย ย ย ย ย ย ย .header("zapiSecretKey", secretKey)ย
ย ย ย ย ย ย ย .header("Authorization", WrapperFunctions.getJWT(addTestsUri,client))ย
ย ย ย ย ย ย ย .header("Content-Type", "application/json")ย
ย ย ย ย ย ย ย .body("{"ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย + "\"issues\": [\"" + String.join("\",\"", issueIds) + "\"],"ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย + "\"method\": \"1\","ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย + "\"projectId\": " + projectId + ","ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย + "\"versionId\": " + versionIdย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย + "}")ย
ย ย ย ย ย ย ย .post(addTestsUri)ย
ย ย ย ย ย ย ย .then()ย
ย ย ย ย ย ย ย .statusCode(200)ย
ย ย ย ย ย ย ย .extract()ย
ย ย ย ย ย ย ย .response();ย
Step 3: Get the Execution IDย
After adding test cases to the test cycle, you need to get the execution ID for each test case. The execution ID is needed to update the execution status of the test case. Here is how you can get the execution ID in Java using Rest Assured:ย
- zephyrBaseUrl =โฏhttps://prod-play.zephyr4jiracloud.com/connectย
- getExecutionIDEndPoint =/public/rest/api/1.0/executions/search/cycle/ย
Response = RestAssured.given()ย
ย ย ย ย ย ย ย .header("Authorization", jwt).header("zapiAccessKey", accessKey)ย
ย ย ย ย ย ย ย .get(zephyrBaseUrl+getExecutionIDEndPoint);ย
ย
int statusCode = response.getStatusCode();ย
ย
if (statusCode >= 200 && statusCode < 300) {ย
ย
ย ย ย JSONObject allIssues = new JSONObject(response.getBody().asString());ย
ย ย ย JSONArray issuesArray = allIssues.getJSONArray("searchObjectList");ย
ย
ย ย ย if (issuesArray.length() == 0) {ย
ย ย ย ย ย ย ย return executionIds;ย
ย ย ย }ย
ย
ย ย ย for (int j = 0; j <= issuesArray.length() - 1; j++) {ย
ย ย ย ย ย ย ย JSONObject jobj = issuesArray.getJSONObject(j);ย
ย ย ย ย ย ย ย JSONObject jobj2 = jobj.getJSONObject("execution");ย
ย ย ย ย ย ย ย String executionId = jobj2.getString("id");ย
ย ย ย ย ย ย ย long issueId = jobj2.getLong("issueId");ย
ย ย ย ย ย ย ย executionIds.put(executionId, String.valueOf(issueId));ย
ย ย ย }ย
}ย
ย
return executionIds;ย
ย
Step 4: Update Execution Statusย
Once you have the execution ID for a test case, you can update its execution status. Here is how you can do it in Java using Rest Assured:ย
- zephyrBaseUrl =โฏhttps://prod-play.zephyr4jiracloud.com/connectย
- updateExecutionStatusEndpoint=/public/rest/api/1.0/executions/ย ย
JSONObject statusObj = new JSONObject();ย
statusObj.put("id", status);ย
ย
JSONObject executeTestsObj = new JSONObject();ย
executeTestsObj.put("status", statusObj);ย
executeTestsObj.put("cycleId", cycleId);ย
executeTestsObj.put("projectId", projectId);ย
executeTestsObj.put("versionId", versionId);ย
executeTestsObj.put("issueId", executionId); // Use the provided execution IDย
executeTestsObj.put("comment", "Executed by ZAPI Cloud");ย
ย
String updateExecutionUri = zephyrBaseUrl + updateExecutionStatusEndpoint + executionId; // Use the provided execution IDย
System.out.println(updateExecutionUri);ย
URI = new URI(updateExecutionUri);ย
int expirationInSec = 360;ย
JwtGenerator = client.getJwtGenerator();ย
String jwt = jwtGenerator.generateJWT("PUT", uri, expirationInSec);ย
System.out.println(jwt);ย
ย
RequestSpecification request = RestAssured.given();ย
request.contentType(ContentType.JSON);ย
request.header("zapiAccessKey", accessKey);ย
request.header("Authorization", jwt);ย
request.body(executeTestsObj.toString());ย
ย
Response = request.put(updateExecutionUri);ย
int statusCode = response.getStatusCode();ย
ย
if (statusCode >= 200 && statusCode < 300) {ย
JSONObject executionResponseObj = new JSONObject(response.getBody().asString());ย
JSONObject descriptionResponseObj = executionResponseObj.getJSONObject("execution");ย
JSONObject statusResponseObj = descriptionResponseObj.getJSONObject("status");ย
String executionStatus = statusResponseObj.getString("description");ย
System.out.println(executionResponseObj.get("issueKey") + "--" + executionStatus);ย
return executionStatus;ย
} else {ย
JSONObject executionResponseObj = new JSONObject(response.getBody().asString());ย
String cycleId = executionResponseObj.getString("clientMessage");ย
System.err.println("Unexpected response status: " + statusCode);ย
return "Failed to update test execution status";ย
}ย
ย
Conclusion:
Automating the test cycle execution in Jira-Zephyr using Rest APIs in Java using Rest Assured is a powerful way to streamline your testing process and ensure that all your test cases are executed efficiently.ย
By following the steps outlined in this blog, you can create a test cycle, add test cases to it, get the execution ID for each test case, and update the execution status. This can save you time and effort in managing your testing process and help you ensure that your software is thoroughly evaluated and of high quality.ย
Rest Assured is an excellent tool for sending RESTful requests, automating API testing and integrating it with Jira-Zephyr can further enhance your testing efforts.ย
Lastly, automating test cycle execution in Jira-Zephyr using Java and Rest Assured provides an efficient and effective solution for AFourtech to organize and run test cases. AFourtech’s Test Automation Services can help save time, minimize errors, and boost productivity by using these tools. Furthermore, using a test automation framework gives a uniform and standardized approach to testing, allowing Afourtech to manage and maintain test cases effortlessly over time. As technology continues to evolve, investing in test automation is essential for AFourtech to stay competitive in today’s fast-paced development environment.
For more information:ย
1 Comment
Hi, I need one zoom meeting session on this topic which is very needed for me to finish the task, could you please help me to join zoom meeting? please help me on this one.