Forum Discussion

krian's avatar
krian
New Contributor
6 years ago

Use API to see if TestRunResult has file(s) attached

I am using the REST and SOAP APIs in Java code to fetch data, especially attachments, from QAComplete projects. When checking if an entity has an attachment, in most cases there is this handy json key "nbr_files" attached to the object in the Get reply.

 

However, when I get down to test run results level, this json key is nowhere to be found. Here's an example:

I call Get on:

http://qacomplete.companyUrl/rest-api/service/api/v2/projects/projId/testruns/testrunId/items/itemId/

And get the following json object:

...

"test_run_results": [
{
"id": testRunResultId,
"test_run_item_id": idNo,
"seq": 1,
"is_stopped_on_fail": false,
"status_code": "Passed",
"step": "Test data<br> <br>",
"expected_result": "xxxxx",
"test_step_id": idNo,
"project_id": projId,
"is_tokenized": false
} ]

...

In this test_run_result item, there is no "nbr_files" key, but I have verified that there is actually a file attached to this entity. That is I can run

soap.getAttachmentList(projId, testRunResultId, "TestRunResults");

and get a list of attachments.

 

So finally, my question is, is it possible to see if a testRunResult item has an attachment without having to call SOAP.getAttachmentList() for every item in the test_run_results array?

 

 

  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Krian,

     

    If you want to use the following methods for the Test Run Results, you should know the "test_run_results/id" value:

    GET /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files

    POST /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files

    GET /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files/{Id}

    PUT /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files/{Id}

    PATCH /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files/{Id}

    DELETE /api/v1/projects/{ProjectId}/{EntityCode}/{EntityId}/files/{Id}

     

    So, you will need to do the following:

    1. Use the GET /api/v2/projects/{ProjectId}/testruns method to find the needed run
    2. To find out the Test Run Result Id, use the following method:

    GET /api/v2/projects/{ProjectId}/testruns/{Id}/items/
    Please see the example:

     

    P.S.
    The attachments for "TestRunResults" are the same files as in the "Actual Result" field for the test steps

    • krian's avatar
      krian
      New Contributor

      Hello Anastasia and thank you for the reply.

       

      Do I understand correctly that the method you suggests involves iterating through each element in the test_run_results array and using the id to check if there is a file attached by using REST rather than SOAP?

       

      I wasn't clear enough in my previous question, that my concern is mostly about the performance of the program. As both methods involve iterating through each item in the array and performing a "get list of files" call, is there any difference in performance between using the REST rather than SOAP api's?

       

      For future updates, it might be helpful for users if you add nbr_files to each item in the test_run_results array that results from calling "/api/v2/projects/{ProjectId}/testruns/{Id}/items/". Then it would be possible to call any version of "get list of files" only on items that actually contain files, which would be a good performance enhancement.