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

Import Test Cases - Linked test case IDs not updating

Hi. I have a large number of test cases that are linked to others by a [Test Case Number]. I understand that when a test case is imported into TestRail it is given a new test case number. The issue that I have is that the linked [Test Case Number] is not updating to the new test case ID that has been generated on the import.

For example:
I have two test cases:
Test case C1
Test case C2 contains a link to [C1].

I have exported the test cases.

When the test cases are imported they have been given a new test reference number but the linked ID has not updated.
Imported test cases:
Test case C3
Test case C4 contains a link to [C1]. This NEEDS to have a link to [C3].

I know I can refer back to the XML used for the import buth when you have over 100 test cases to update this can be difficult, especially as there is no option to filter the test cases by preconditions or steps.

As none of the actual images within the test case have been imported I downloaded the backup. How do i import this into a new TestRail cloud account?

Any help would be much appreciated.

Thanks,
Claire

Hi Claire,

I believe this should be possible using the api and doing some creative shuffle work using arrays. The one limitation I think is needing to be certain there are no duplicate case titles, and the approach below may be an oversimplified example not knowing your complete situation. The hash keys I provided are symboling the example you shared with 1 update to do, but we know there are over 100 cases to be processed.

  1. First api call get_cases would fetch all the test cases from the original project, and store these into an array perhaps called original_cases_array.
  2. Create a second array called cases_with_links. The structure would be loop through each case in the first array, and if there is a link, populate a record into the cases_with_links. The cases_with_links array could include hash records consisting of something like {c1_title:‘Case 1 Title’, link_to_c1:“https://…testrail.net/case_id/0001”, c2_title:“Case 2 Title”, c3_id:null, c4_id:null}. To get c1_title, you would need to parse the case_id from the end of the link, and locate the c1 record in original_cases_array and finally get the title).
  3. On the project with the imported cases, run the same get_cases api call and store these into an array called imported_cases_array.
  4. Programmatically iterate through every record in cases_with_links array, with the goal of populating the c3_id and imported_c4_id fields. It would be about finding the unique test case titles that match in the imported_cases_array.
  5. Loop through cases_with_links again, and update the links with the new ones from c3_id
  6. Loop through cases_with_links one last time, this time hitting the update case endpoint in TestRail. E.g. update_case/c4_id. The post body is going to supply the updated link.

This looks like a lot of work, but it could be a fun learning experience for you with a scripting language. Here is the url for getting started. http://docs.gurock.com/testrail-api2/start
If this seems to much contact a developer on your team I’m sure they would be happy to help you get going!

As for the second part, I think you need to contact support if there is a chance to import or restore a database into a new project or repo with images. The api only has an option to add attachment for a result I think but not an attachment for case fields themselves. http://docs.gurock.com/testrail-api2/reference-attachments. The solution might be a combination of doing a restore into a new project, and if the links are invalid or outdated, follow the approach shared above.

1 Like