update the execution status of a test case using jira rest api

rayudu October 23, 2017

Hi All, Warm Regards, I have created test cases in JIRA test management tool. Automated the test cases using ready API. I want to update the test case status (Pass/Fail) Using jira rest api. Can some one pls help.

I referred the following link:

https://docs.atlassian.com/jira/REST/cloud/#api/2/workflowscheme-updateDraftDefault

 

 

6 answers

1 vote
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2020

Hi everyone,

This question is rather old, but I wanted to try to update the answers here.  Natively, Jira does not do test management.  There are however several plugins in Marketplace that can help make that a reality.  A few that I am aware of are Zephyr, Xray, TM4J, and many more which you can find in a search of Marketplace.

I am not sure which one might have been referred to by 'Jira test management tool'.  I am afraid that title is a bit vague to me, and sometimes plugins/apps can have their titles change in marketplace.

That said, because these apps add functionality to Jira, I don't have the expectation that Jira's native REST API will be able to manipulate these entities like standard Jira issue types.  As such, it would be best to reach out to the plugin vendor to see if there does exist a REST API for managing these.  I found some such as

I hope this helps.  If not, it would probably be best to reach out to the specific plugin vendor for support on this topic.

Thanks

Andy

0 votes
Megha Hulage
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 8, 2024

@rayudu you can update Test cases status in jira using Xray api if you have used X-ray to test management 

0 votes
Megha Hulage
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2024

12:52
To update the status of a test in a test execution in Jira using the Xray API, you'll need to follow these steps:

Get an Authentication Token: Xray API requires authentication. You need to generate a token using your Xray client ID and secret.

Update the Test Execution Status: Once you have the token, you can use it to update the status of a test within a test execution.

Here is a step-by-step guide:

Step 1: Get an Authentication Token
Send a POST request to the authentication endpoint with your client ID and secret.

Request:

sh
Copy code
curl -X POST "https://xray.cloud.getxray.app/api/v2/authenticate" \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
Response:

json
Copy code
"YOUR_JWT_TOKEN"
Step 2: Update the Test Execution Status
Now, use the token to update the status of a specific test within a test execution.

Request:

sh
Copy code
curl -X POST "https://xray.cloud.getxray.app/api/v2/import/execution" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"testExecutionKey": "TEST_EXECUTION_KEY",
"tests": [
{
"testKey": "TEST_KEY",
"status": "STATUS"
}
]
}'
Parameters:

testExecutionKey: The key of the test execution.
testKey: The key of the test you want to update.
status: The new status for the test. It can be one of the following: PASS, FAIL, TODO, EXECUTING, ABORTED.
Example
Let's say you want to update test ABC-123 within test execution TE-456 to PASS. Here is what the request would look like:

sh
Copy code
curl -X POST "https://xray.cloud.getxray.app/api/v2/import/execution" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"testExecutionKey": "TE-456",
"tests": [
{
"testKey": "ABC-123",
"status": "PASS"
}
]
}'
Full Script Example
Here's a full example using Python and the requests library to automate the process:

python
Copy code
import requests

# Step 1: Authenticate and get the token
auth_url = "https://xray.cloud.getxray.app/api/v2/authenticate"
auth_payload = {
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}
auth_headers = {
"Content-Type": "application/json"
}
response = requests.post(auth_url, json=auth_payload, headers=auth_headers)
token = response.json()

# Step 2: Update the test execution status
execution_url = "https://xray.cloud.getxray.app/api/v2/import/execution"
execution_payload = {
"testExecutionKey": "TE-456",
"tests": [
{
"testKey": "ABC-123",
"status": "PASS"
}
]
}
execution_headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
execution_response = requests.post(execution_url, json=execution_payload, headers=execution_headers)

print(execution_response.status_code)
print(execution_response.json())
Make sure to replace YOUR_CLIENT_ID, YOUR_CLIENT_SECRET, TE-456, and ABC-123 with your actual Xray client ID, secret, test execution key, and test key respectively.

This script will authenticate with Xray, get a token, and then use that token to update the status of a test within a test execution.

0 votes
rayudu October 24, 2017

Also, First i want to read the test cases which i have drafted in JIRA test management. Then want to update the test case status to PASS/FAIL using jira REST API.

 

Please do the needful.

Jenkins Auto March 5, 2019

Hi rayudu,  How are you?

Are you able to update the status to PASS/FAIL using REST API now?

I want to do the same and not able to after searching for so long. I posted this question. 

I am able to query using JQL as suggested but still not able to filter and update the status of my test execution

https://community.atlassian.com/t5/Jira-questions/Retrieving-and-Updating-an-issue-s-status-via-the-rest-API/qaq-p/1025142?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_answer&utm_content=topic

Hope to know how it went for you.

Thanks

Sam

0 votes
rayudu October 24, 2017

Hi Gregor,

Thanks for reply.

Using post method:

https://xxxxxx/rest/api/2/issue/testcaseid/transitions?expand=transitions.fields 

Payload:-

{
"update":{
"name": "In Progress",
"id": "3"
},

"transition": {
"id": "21"
}
}

Still not working

Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2017

Do you have any error message?

0 votes
Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2017
Bindhu November 25, 2019

Hi Gregor,

The above link which u have shared is for changing the status of issue. Can you please share the details of how to change the execution status of any issue?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events