Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleXray REST API v1 and v2 on Xray server/DC. What are the differences?

The REST API v2.0 for Xray server/DC is an extension to the original v1.0 of the REST API. Therefore, all existing endpoints on v1.0 also exist on v2.0 (even if you don't see that in the docs); you just need to replace the "1.0" by "2.0" on the URL.

Example:

  <jira_base_url>/rest/raven/1.0/api/test/{key}/testexecutions   becomes   <jira_base_url>/rest/raven/2.0/api/test/{key}/testexecutions

Use cases

Importing test automation results to Xray using Xray JSON format

Importing automation results into Xray is a very common use case.

At high-level, the flow can be depicted in the following diagram.

Image Removed

There are some initial steps that need to be performed on the tool prior to importing results. The creation of the Test issue in Xray, could be done at any moment prior to importing results(manually or via the API).

The recommended way for importing results is by using the Xray JSON format and one of the respective endpoints (server/DC, cloud), which is quite flexible and very straightforward if you wish just have overall visibility of the test result, for example. 

There are a bunch of test report formats supported (e.g., JUnit XML, Xray JSON, etc), which may be slightly different for Xray Cloud and for Xray server/DC. Depending on the report format and whether you're using Xray Cloud or server/DC, different capabilities will be available (server/DC, cloud).


In this case, we'll use the Xray JSON format as means to encapsulated the test results.

At high-level, the flow can be depicted in the following diagram.


Image Added

There are some initial steps that need to be performed on the tool prior to importing results. The creation of the Test issue in Xray, could be done at any moment prior to importing results(usually manually but could also be done via the APIThere are also other well-known formats, each one providing different capabilities (server/DC, cloud).


Expand
titleClick here to see some subtle differences on Xray JSON format between Xray server/DC and Cloud...

Xray JSON format has the same syntax but to the distinct nature of Jira server/DC and Jira Cloud (and also Xray), there are some nuances.



Xray Server/DCXray CloudNotes
values for "status" attribute, for each "test" and "step" elements"PASS", "FAIL", "TODO", "EXECUTING""PASSED", "FAILED", "TO DO", "EXECUTING"
"user" attributeusername of Jira user

name of Jira user.

Usually, you don't need to specify the user as by default it is assigned to the user related to the given credentials. 

With Xray Cloud, you can use the "userId" attribute instead and in that case you need to use the hash of the user (you can see it as the ending part of the URL of the user profile)

...

Scenario1: report test automation results to existing Tests in Xray

In this case we're assuming:

  • Test issue(s) already exist in Xray (they could have been created as usual by a user or by some automation process)
  • An automated test equivalent exist in the external tool/code, for each Test

And we want to...

...

Code Block
languagejs
themeDJango
titleJSON body payload
collapsetrue
{
    "info": {
        "summary": "Execution of automated tests for release",
        "description": "This execution was automatically created when importing execution results from an external source",
        "project": "BOOK",
        "version": "1.0",
        "revision": "123",
        "startDate": "2021-07-14T11:47:35+01:00",
        "finishDate": "2021-07-14T11:53:00+01:00",
        "testEnvironments": [
            "chrome"
        ]
    },
    "tests": [
        {
            "testKey": "BOOK-429",
        	"start": "2021-07-14T11:47:35+01:00",
        	"finish": "2021-07-14T11:53:00+01:00",
            "comment": "invalid user",
            "status": "FAIL",
            "evidences" : [
              {
               "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkG...."
               "filename": "screenshot.jpg",
               "contentType": "image/jpeg"
               }
            ]
        },
        {
            "testKey": "BOOK-458",
        	"start": "2021-07-14T11:47:35+01:00",
        	"finish": "2021-07-14T11:53:00+01:00",
            "status": "PASS"
        }
    ]
}

After importing results, a Test Execution would be created containing the results for the two tests; the details of the execution screen show the data of the Test Run, including its status, comment, timings, among other.

Image Removed

Image Removed

...

}


After importing results, a Test Execution would be created containing the results for the two tests; the details of the execution screen show the data of the Test Run, including its status, comment, timings, among other.


Image Added

Image Added


Xray Cloud

The first thing to do would be to obtain a token, using the Client Id and Client secret from the corresponding API key on Xray. 

This would require performing a HTTP request to the authentication REST API endpoint from Xray Cloud.

Then a second request could be made to upload the test automation results; in the following example the Xray JSON is stored on a payload.json file.

Code Block
languagebash
themeDJango
titleexample of a API request with "curl" using basic authentication
collapsetrue
token=$(curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "32A27E69B0AC4E539C14016437000000","client_secret": "d62f81eb9ed859e11e54356dd8a00e4a5f0d0c2a2b52340776f6c7d6d7000000" }'  https://xray.cloud.getxray.app/api/v2/authenticate)

curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"payload.json" "https://xray.cloud.getxray.app/api/v2/import/execution

...