如何使用 Xray Rest API 将测试执行添加到测试计划?
How to add Test Execution to a Test Plan with Xray Rest API?
我正在尝试添加一个 Test Execution to a Test Plan using Xray Rest API & Axios. I have already created an API key 并像这样成功验证:
const axios = require('axios');
const { argv } = require('yargs');
const { clientId, clientSecret } = argv;
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
};
const authenticateXray = async () => {
await axios({
method: 'post',
url: `https://xray.cloud.xpand-it.com/api/v2/authenticate`,
headers,
data: {
client_id: clientId, // my created client id goes here
client_secret: clientSecret, // my created client secret goes here
},
})
.then(res => console.log(`Xray authentication response status was: ${res.status}`)) // 200!
.catch(e => {
throw new Error(e.response.data.error);
});
};
然后,我调用并传递了一些 param
之前在创建 Test Plan
& Test Execution
时收集的值,如下所示:
await axios({
method: 'posts',
url: `https://xray.cloud.xpand-it.com/api/internal/testplan/${createdTestPlan.data.id}/addTestExecs`,
data: {
0: createdTestExecIssue.data.id,
},
});
但是,我收到此错误:(node:46352) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
。我能够使用来自 Jira Rest API 的另一个端点 link Test Execution
到 Test Plan
,但我想添加它,请查看下面的屏幕截图以供参考.
我能够通过像这样以不同方式传递 data
来解决这个问题:
await axios({
...
...
data: [`${testExecutionId}`],
});
& 在 Request Header
中传递 X-acpt
key/value 对,如下所示:
'X-acpt': `encodedCharaterGoesHere-YouNeedToretrievUsingNetworkTabInChrome`,
我的请求是这样结束的:
await axios({
method: 'post',
url: `https://xray.cloud.xpand-it.com/api/internal/testplan/${testPlanId}/addTestExecs`,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-acpt': `encodedCharaterGoesHere-YouNeedToretrievUsingNetworkTabInChrome`,
'X-Powered-By': 'Express',
},
data: [`${testExecutionId}`],
});
您可以使用 graphQL api 执行此操作,只需替换 YourTestPlanID 和 yourTestExecutionId。
const response = await axios({
method: 'post',
url: 'https://xray.cloud.xpand-it.com/api/v1/graphql',
data: {
query:
`mutation {
addTestExecutionsToTestPlan(
issueId: "YourTestPlanID",
testExecIssueIds: ["yourTestExecutionId"]) {
addedTestExecutions
warning
}
}`
},
headers: {
Authorization: `Bearer TOKEN obtained using the authentication api`,
'Content-Type': 'application/json' }
});
我正在尝试添加一个 Test Execution to a Test Plan using Xray Rest API & Axios. I have already created an API key 并像这样成功验证:
const axios = require('axios');
const { argv } = require('yargs');
const { clientId, clientSecret } = argv;
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
};
const authenticateXray = async () => {
await axios({
method: 'post',
url: `https://xray.cloud.xpand-it.com/api/v2/authenticate`,
headers,
data: {
client_id: clientId, // my created client id goes here
client_secret: clientSecret, // my created client secret goes here
},
})
.then(res => console.log(`Xray authentication response status was: ${res.status}`)) // 200!
.catch(e => {
throw new Error(e.response.data.error);
});
};
然后,我调用并传递了一些 param
之前在创建 Test Plan
& Test Execution
时收集的值,如下所示:
await axios({
method: 'posts',
url: `https://xray.cloud.xpand-it.com/api/internal/testplan/${createdTestPlan.data.id}/addTestExecs`,
data: {
0: createdTestExecIssue.data.id,
},
});
但是,我收到此错误:(node:46352) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
。我能够使用来自 Jira Rest API 的另一个端点 link Test Execution
到 Test Plan
,但我想添加它,请查看下面的屏幕截图以供参考.
我能够通过像这样以不同方式传递 data
来解决这个问题:
await axios({
...
...
data: [`${testExecutionId}`],
});
& 在 Request Header
中传递 X-acpt
key/value 对,如下所示:
'X-acpt': `encodedCharaterGoesHere-YouNeedToretrievUsingNetworkTabInChrome`,
我的请求是这样结束的:
await axios({
method: 'post',
url: `https://xray.cloud.xpand-it.com/api/internal/testplan/${testPlanId}/addTestExecs`,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-acpt': `encodedCharaterGoesHere-YouNeedToretrievUsingNetworkTabInChrome`,
'X-Powered-By': 'Express',
},
data: [`${testExecutionId}`],
});
您可以使用 graphQL api 执行此操作,只需替换 YourTestPlanID 和 yourTestExecutionId。
const response = await axios({
method: 'post',
url: 'https://xray.cloud.xpand-it.com/api/v1/graphql',
data: {
query:
`mutation {
addTestExecutionsToTestPlan(
issueId: "YourTestPlanID",
testExecIssueIds: ["yourTestExecutionId"]) {
addedTestExecutions
warning
}
}`
},
headers: {
Authorization: `Bearer TOKEN obtained using the authentication api`,
'Content-Type': 'application/json' }
});