Get all test cases from a folder and it's sub-folders

For Automation purposes I need to be able to fetch all test cases in a folder as well as any test cases in the sub folders in that folder.

There is very limited info in the api docs imo for how the filter and mapping works and what are acceptable values.

If I call testcase/find with:

suite_id = 5
project_id = 1
{
    "pagination": {
        "offset": offset,
        "limit": limit,
    },
    "map": {
        "entities": ["testcase", "testcase_folder"],
        "ids": {"testcase_folder_id": suite_id},
    },
    "filter": {"project_id": project_id},
},

Then I’ll get all tests inside tcf-5 but if it contains a subfolder I get nothing on this subfolder existing or the cases inside the subfolder.

How can I go about getting all the testcases in a folder tree?

Right, I was missing that I can put filter inside the map, had no clue this was allowed!

In the end what worked was calling the graph mentioned above to get the list of ID’s and then call testcase/find with:

{
    "pagination": {
        "offset": offset,
        "limit": limit,
    },
    "map": {
        "entities": ["testcase", "testcase_folder"],
        "filter": {"testcase_folder_id": testcase_folder_ids},
    },
    "includeTotalCount": True,
    "filter": {"project_id": project_id},
}

This will return all the test cases for a given testcase_folder and their sub-folders (within the pagination limits).

Hi Asgeir,

There is currently no direct way to get testcases from subfolders, but here is a way to do it in 2 steps:

POST /api/v1/graph/visit
{
  "template": "tcf-nested",
  "ids": [1234],
  "projectId": 1
}

This runs a pre-defined graph query to retrieve the nested testcase folder ids (This endpoint is currently not yet documented but you can assume it to be stable)

The result should look like this:

{
	"result": {
		"ids": [
			1235,
			1237,
			1238
		]
	},
	...
}

Now

  1. take the result.ids array from this response, add your original folder id (if needed - the result does not include the root itself)
  2. and use the array in your query instead of the “ids: {…}” line use
    "filter": { "testcase_folder_id": [1234,1235,1237,1238] }

We are aware that our API docs could use improvements and are working on adding more documentation and more examples. We are also considering adding easier-to-use endpoints for common use cases.

Regards,
Michael

Trying to make the second request work once I have all the IDs and getting 400 Error back.

Payload:

{
                "pagination": {
                    "offset": offset,
                    "limit": limit,
                },
                "map": {
                    "entities": ["testcase", "testcase_folder"],
                    "ids": {"testcase_folder_id": testcase_folder_id},
                },
                "includeTotalCount": True,
                "filter": {"testcase_folder_id": testcase_folder_id},
            }

testcase_folder_id is the array of IDs from previous mentioned request.

400 - Validation failed because no alternatives match: ‘Expected number at DataReadParams.map.ids.testcase_folder_id, Expected null at DataReadParams.map.ids.testcase_folder_id’ at DataReadParams.map.ids.testcase_folder_id

Clearly something missing in what I’m allowed to pass into the filter and map here?

Hi Asgeir,

  1. You can drop the filter for the folder id, this does not exist in the context of the base entity (which is testcase)
  2. In the the “map”, the testcase_folder_id must be a number (not a numeric string)

I tried with these changes and it works for me

Regards,
Michael

Your previous response suggested I could pass in an array of ints to the map:

"map": {
                    "entities": ["testcase", "testcase_folder"],
                    "ids": {"testcase_folder_id": testcase_folder_id},
            },

Where test_case_folder_id = [1,2,3,4]

Or is my only option to call this once for each of the values 1,2,3,4, etc ?

This works only for filters, not for “ids”, which expects a list of objects with the mapped entity ids

replacing the “ids” with “filter” and maybe renaming the testcase_folder_id variable to testcase_folder_ids :wink: should work