Before following the guide, if you have any doubts about how to create an Xray API account and use Insomnia, you can check this article.

It is indeed possible to both export and import Tests that include Step attachments, and this guide will walk you through the process in detail. The steps outlined here will help you manage your Test data effectively, ensuring that any attachments linked to individual Test Steps are retained during the export and import procedures.

To help illustrate how this works, we will use a Test already created as an example. By following along with this specific Test, you will gain a clearer understanding of how to handle the export and import operations, ensuring that all attachments and related data are successfully transferred:

With the gettest mutation (documentation) you will get the following output:
Note: The ID of the Test you can get by exporting the XML of the issue

{
    "data": {
        "getTest": {
            "issueId": "64459",
            "testType": {
                "name": "Manual",
                "kind": "Steps"
            },
            "steps": [
                {
                    "id": "7a192827-3b1d-4731-8063-a071ec38a95f",
                    "data": "",
                    "action": "I choose the operation of the calculator *Subtraction*",
                    "result": "The operation must appear selected.",
                    "attachments": []
                },
                {
                    "id": "0ff5b22b-cd6e-4c82-b248-792491ff0c45",
                    "data": "I1: 5\nI2: 2",
                    "action": "I enter the input into the calculator",
                    "result": "",
                    "attachments": []
                },
                {
                    "id": "ad75f799-bbd5-4e12-83a6-ac532547720d",
                    "data": null,
                    "action": "I press the *Calculate* button",
                    "result": "The result *3* should be displayed in the screen, on the right of the \"=\" sign.",
                    "attachments": [
                        {
                            "id": "2815b895-f944-4211-b9d5-61a5ccc03049",
                            "filename": "Screenshot_1.png"
                        }
                    ]
                }
            ]
        }
    }
}


 We will need to adapt the file to be able to import them to the other Cloud instance; it should look like the following:

[
    {
        "testtype": "Manual",
        "fields": {
            "summary": "This tests the Subtraction of two numbers.",
            "project": {
                "key": "LPSS"
            }
        },
        "steps": [
            {
                "action": "I choose the operation of the calculator *Subtraction*",
                "data": "",
                "result": "The operation must appear selected."
            },
            {
                "action": "I enter the input into the calculator",
                "data": "I1: 5\nI2: 2",
                "result": ""
            },
            {
                "action": "I press the *Calculate* button",
                "result": "The result *3* should be displayed in the screen, on the right of the \"=\" sign."
            }
        ]
    }
]


Now, regarding the attachments part, the GraphQL function will give you a URL that you must use on the Attachments API. Please note that this uses the generated URL on point 1, with the authentication method as well.

Next up, upload the attachment to the test step. Now, we need to fetch the ID of the test step. To do that, you need to perform another GraqhQL request for that new Test that you created in the destination Cloud instance:

In this case, the id of the new Test is 64460:

https://xray.cloud.getxray.app/api/v2/graphql


 

With this ID, we can then update the test step with the mutation *update TestStep* and pass the information of the attachment to be imported encoded in base 64.
It's important that you follow the structure that we provide for that specific mutation in our documentation here

After that, and in our case, it should look like this:
{code:java}

mutation {
    updateTestStep(
        stepId: "69335252-22c5-4574-b5f6-7411e2fd068b"
        step: {
            action: "I press the *Calculate* button"
            attachments: {
                add: {
                    filename: "Screenshot_1.png"
                    mimeType: "image/png"
                    data: "iVBORw0KGgoAAAANSUhEUgAAAagAAAHbCAYAAACeBA6vAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAP+lSURBVHhe7J0HeJTF9sb/13L1qrdfb/faCxZUeu+9914UUAEVUeyIioAUUQQEBUQFQQSk9957b2nbs5vdbBoh9Pr+zzubD0OYhCQkIZDZ5/k9m2z5vm+/mTnvnJkzZ/4vKmo/DAaDwWAoaBiBMhgMBkOBxAiUwWAwGAokRqAMBoPBUCAxAmUwGAyGAokRKIPBYDAUSIxAGQwGg6FAYgTKYDAYDAUSI1AGg8FgKJAYgTIYDAZDgcQIlMFgMBgKJEagDNc9jmVz4BzwDuxNq8NTrzycHRrDOeQDOJbO0X7eYDBcHxiBMlzXOJbPRfSn7yOmQyP4GlaGv34FxDSthphOTeD9qA+ci2YiKnyP9rsGg6FgYwTKcF1j/+xjeDs2RmyDipcRaFdfiZR97RLYDu7Uft9gMBRcjEAZrk8i9sK2byscPTvCW6+8VqBIoFVteD7/BPaNK9R3tMcyGAwFEiNQhusS26Gdao4p5qW2WmFKj2v..."
                }
            }
        }
    ) {
        warnings
    }
}


And the attachment goes to the step looking like this:


And that's it!

  • No labels