Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Using API to clone latest matching test plan

#1

Hello,

I am trying to automate creation of test plan when a new release is made and tests are auto-triggered. To do this, I need to clone (similar to UI re-run function) the latest test plan matching a specific naming criterion. So I need to do the following:

  • Find a plan matching the parameters used to run test. If found, upload results for it.
  • If not found, create plan to upload using following steps:
    – Find the latest (created) test plan with specific strings in its name. For example, latest plan with “windows” and “firefox” in the plan name. Plan can be open or closed.
    – Create a new plan with specific name. For example, “Windows, Firefox, build 123”.
    – Clone every configuration in the previous plan (from step 1) to new plan.
    – Copy selection of enabled tests from previous plan to new plan.
    – Upload results to new plan.

I guess there is functionality in the API to implement these steps. However, a question:

What happens if multiple tests run in parallel and each one queries the API for the test plan? Will there be a race condition where multiple new test plans can be generated? Multiple tests may request for the matching plan, get response it does not exists, decide to create a new plan, and before doing so, another test also created it (resulting in two identical plans created) ? How to avoid?

Thanks,

0 Likes

#2

Hi @uliuli,

TestRail’s API doesn’t have a pre-configured ‘re-run’ method for test runs and plans, however you should be able to achieve the same functionality via the API using the ideas you described.

However, if you do have multiple scripts running in parallel for the same process, there is the possibility of your script creating multiple test plans.

If two plans are created with the same details, this wouldn’t cause issues within TestRail itself, as each plan, run, test, etc. would have a unique ID. When retrieving a list of entities via the API, many responses would include the most-recently added item as the first result, so having two plans with the same details might result in your script submitting data to the incorrect plan or run.

With this in mind, if multiple similar test plans would be problematic, we would recommend ensuring your script does not create multiple plans in parallel or handles these extra plans to suit your needs.

Hope this helps,
Jon

0 Likes

#3

OK, thanks for the reply. I think I will just try to create plans and upload to the latest created. The kind of race-condition that would create more than one plan should be very rare, and one can just delete the extra plan. Other kinds of tricks would just get more complex than needed.

After some API exploration, I see I need something to copy the configurations and other details from, when creating a new plan with the API. I see I can use get_plan(old_plan_id) to get all the details to copy into a new plan.

However, I do not see a way to simply request the latest plan(s). I can request all plans, sort by creation date, and use the newest. But if there are a large number of plans accumulated over time, it will cause large network requests and require me to implement pagination logic when going over 250 plans (API limit).

Is there some way to just request TestRail to give me the latest created plan for a project, or N latest plans created (with the API)?

0 Likes

#4

Hi @uliuli,

It would be possible to limit the number of responses with the ‘get_plans’ method by using the ‘limit=N’ filter, which would allow you to limit the result to N results.

You can also use this filter combined with other filters to limit the number of plans received and require less processing.

Regards,
Jon

0 Likes