Can we add test cases to a Test run by the "test case ID" via API

Hi,

let me give you the background of my approach. I use Playwright as an automation tool framework

  1. I have a set of test cases listed in the Testiny. Let’s say 10
  2. I have only 5 test cases which run on the Azure Pipeline every time
  3. for a given release version, I want to create a test run named after the version with those 5 test cases via API
  4. And upload the results to the test run via API

Could you please guide me here… ?

Below are the approaches I have done so far:

  1. I have created a test plan but couldn’t add the test cases to it via API
  2. So I have created a test plan manually and added 5 test cases manually
  3. I have created a Test run via API with the test plan ID and every time it creates a new one
  4. I don’t see the Test cases added by doing like this

Kindly let me know if i am missing anything

Hi,

Adding test cases to a test run via API is almost the same as setting results for a test case in a test run: You create a mapping between test case and test run and also pass in the result.

The below API call uses the add_or_update operation, so you can basically use it to add a test case or update it’s result within a test run:

curl -L -X POST 'https://app.testiny.io/api/v1/testrun/mapping/bulk/testcase:testrun?op=add_or_update' \
  -H 'Content-Type: application/json' \
  -H 'X-Api-Key: <API_KEY_VALUE>' \
  --data-raw '[{
      "ids": { "testcase_id": 1234, "testrun_id": 3 },
      "mapped": { "result_status": "PASSED" }
    }]'

Please update the API-Key, the test case id + the run id to the respective values. The allowed values for the result status are NOTRUN,PASSED,FAILED,BLOCKED,SKIPPED as you can see in the API documentation:

If you’re adding/updating test case results from a result file, e.g. from a JUnit XML file, using the Testiny CLI may be easier as explained here:

Hope this helps you get going :slight_smile:

Regards,
Alex

from the below API load

--data-raw '[{ "ids": { "testcase_id": 1234, "testrun_id": 3 }, "mapped": { "result_status": "PASSED" } }]'

currently, this allows one at a time… can this allow multiple testcase_ids and multiple results at a go?

The API takes an array, so just pass in multiple objects, e.g.:

curl -L -X POST 'https://app.testiny.io/api/v1/testrun/mapping/bulk/testcase:testrun?op=add_or_update' \
  -H 'Content-Type: application/json' \
  -H 'X-Api-Key: <API_KEY_VALUE>' \
  --data-raw '[{
      "ids": { "testcase_id": 1234, "testrun_id": 3 },
      "mapped": { "result_status": "PASSED" }
    }, {
      "ids": { "testcase_id": 12345, "testrun_id": 2 },
      "mapped": { "result_status": "FAILED" }
    }]'

You can specify any test case and any test run, so you could also update multiple test runs in one go.

Regards,
Alex

I want to try it from the API using python

Sure, no prob, any programming language will do that can send API requests. The API documentation even has some code snippets for Python to start with.

Regards,
Alex