你好,我一直在开发一个 python 脚本来使用 REST API 更新 Jira 上的 Xray 测试
BaseUrl/rest/raven/2.0/api/import/execution
但是当我运行 python 脚本时,我收到了这个错误
Error instantiating bean. Field(s) tests -\\u003e customFields -\\u003e name do not follow the correct format.
url = "BaseUrl/rest/raven/2.0/api/import/execution"
personal_access_token = "******"
# Test execution JSON payload
test_execution = {
"testExecutionKey": "T4SV-T561",
"info": {
"revision": "1.0.42134",
"testEnvironments": [
"windows",
"Linux"
]
},
"tests": [
{
"testKey": "T4SV-T415",
"status": "PASS",
'executedBy':'*****@**.com',
"comment": "Test passed successfully",
"start": "2023-09-07T11:47:35+01:00",
"finish": "2023-09-07T11:50:56+01:00",
"customFields": [
{
"id": 1,
"name": "Name1",
"value": "[https://www.#.net"
},
{
"id": 2,
"name": "Name2",
"value": "https://www.#.net"
}]
}
]
}
headers = {"Content-Type": "application/json",'Authorization': 'Bearer ' + personal_access_token}
# Send the POST request
response = requests.post(url, headers=headers, data=json.dumps(test_execution),verify=False)
如果我从 JSON 中删除
customfield
部分,则 POST 请求工作正常,没有错误,所以我不知道应该以哪种格式添加自定义字段,因为我得到的格式与 BaseURL/rest/raven/2.0/api/project/{ID}/settings/customfields/testruns
中的格式完全相同
只需从
name
对象中取出 customFields
属性即可。您需要使用 id
以及 value
。
请参阅下页,了解有关 customFields 对象的更多信息。该页面还具有 Xray JSON 格式的 JSON 模式。
你的脚本会变成这样:
url = "BaseUrl/rest/raven/2.0/api/import/execution"
personal_access_token = "******"
# Test execution JSON payload
test_execution = {
"testExecutionKey": "T4SV-T561",
"info": {
"revision": "1.0.42134",
"testEnvironments": [
"windows",
"Linux"
]
},
"tests": [
{
"testKey": "T4SV-T415",
"status": "PASS",
'executedBy':'*****@**.com',
"comment": "Test passed successfully",
"start": "2023-09-07T11:47:35+01:00",
"finish": "2023-09-07T11:50:56+01:00",
"customFields": [
{
"id": 1,
"value": "[https://www.#.net"
},
{
"id": 2,
"value": "https://www.#.net"
}]
}
]
}
headers = {"Content-Type": "application/json",'Authorization': 'Bearer ' + personal_access_token}
# Send the POST request
response = requests.post(url, headers=headers, data=json.dumps(test_execution),verify=False)