2

I can use jira package with python and upadate or fetch issue details from JIRA. But I want to know how to import test execution results into XRAY JIRA using post requests in python. I have done this already using JAVA and XRAY REST API with a json file for cucumber tests.

Can't figure out the same thing to be done in python for manual tests. Please note the requirement is to update manual test status as PASS/FAIL in a test execution in XRAY in an automated approach using python.

1 Answers1

5

Here's the solution.

First thing, use the jira api to create a new issue of the "Test Execution" type:

fields_dict = {
    'project': 'AB',
    'summary': 'New execution',
    'description': 'Test execution creation via python',
    'issuetype': {'name': 'Test Execution'}
}

test_execution = jira.create_issue(fields = fields_dict)

Now we need to associate tests with this test execution. For this example, let's associate a single test called "AB-3". Don't forget to include auth details for this POST. You can associate test sets in the same manner, ie, "AB-3" could be a single test or a test set.

requests.post("https://my.jira.com/rest/raven/1.0/api/testexec/" + test_execution.key + "/test", json{"add": ["AB-3"]})

This creates a unique id for each test we have associated with this test execution. We will need this unique id to update the execution status.

r = requests.get("https://my.jira.com/rest/raven/1.0/api/testexec/" + test_execution.key

test_id = r.json()[0]['id']

If you have more than one test, use a loop of course. I'm just subscripting to the first item since I know we only have one test.

Then to update execution status, we do a PUT:

requests.put("https://my.jira.com/rest/raven/1.0/api/testrun/" + str(test_id) + "/status?status=PASS")

You can use "PASS" or "FAIL", etc. Don't forget to auth!

10 Rep
  • 2,217
  • 7
  • 19
  • 33
cat pants
  • 1,485
  • 4
  • 13
  • 22