1

我正在尝试使用Xray Rest APIAxios将测试执行添加到测试计划中。我已经创建了一个 API 密钥并成功通过了身份验证,如下所示:

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. 我能够将 a 链接Test ExecutionTest Plan使用 Jira Rest API 的另一个端点,但我希望添加它,请查看下面的屏幕截图以供参考。

在此处输入图像描述

4

2 回答 2

0

我能够通过data不同的方式来解决这个问题,如下所示:

await axios({
    ...
    ...
    data: [`${testExecutionId}`],
});

& 像这样传递X-acpt键/值对Request Header

'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}`],
  });
于 2020-12-11T22:55:32.213 回答
0

您可以使用 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' }
});
于 2021-01-07T08:53:38.190 回答