I have written the following python code:
import requests
import json
import os
xray_cloud_base_url =
"https://xray.cloud.getxray.app/api/v2"
client_id = provided
client_secret = provided
# endpoint doc for authenticating and obtaining token from Xray Cloud: https://docs.getxray.app/display/XRAYCLOUD/Authentication+-+REST+v2
headers = {
'Content-type':
'application/json', 'Accept':
'text/plain'}
auth_data = {
"client_id": client_id
, "client_secret": client_secret }
response = requests.post(
f'{xray_cloud_base_url
}/authenticate', data=json.dumps(auth_data)
, headers=headers)
auth_token = response.json()
with open('sample.xml', 'r') as file:
junit_xml_content = file.read()
# Prepare headers
headers = {
'Authorization': 'Bearer ' + auth_token,
'Content-Type': 'application/xml',
'X-Info-JSON': json.dumps({
"fields": {
"project": {
"key": "DX"
},
"summary": "Test Execution for JUnit tests",
"description": "This contains test automation results",
"components": [{"name": "QA"}],
"issuetype": {
"name": "Test Execution"
}
# "fixVersions": [{"name": "v1.0"}]
}
})
}
url = f'{xray_cloud_base_url}/import/execution/junit?projectKey=DX&testExecKey=DX-79900'
response = requests.post(url, headers=headers, data=junit_xml_content)
# Send the POST request
# response = requests.post(f'{xray_cloud_base_url}/import/execution/junit', headers=headers, data=junit_xml_content)
# Process the response
if response.status_code == 200:
print('Test execution results successfully imported.')
else:
print(f'Failed to import test execution results. Status code: {response.status_code}')
print(f'Response: {response.text}')
Error:
Failed to import test execution results. Status code: 400
Response: {"error":"Error creating issues in Jira! - components: Components is required."}
I have given the right component name as i have matched with JIRA ticket.