Assistance Needed for Importing and Exporting Test Suites and Test Plans Across DevOps Tenants

Sathishkumar G 0 Reputation points
2024-07-08T12:37:38.3033333+00:00

Description:

Dear Microsoft Support Team,

Need to assistance with the process of importing and exporting test suites and test plans across different Azure DevOps tenants.

Source Tenant:

Organization: [ReposMigration]

Project: [VSO Repos Migration]

Target Tenant:

Organization: [sathishkumarg0353]

Project: [migration]

Please let me know if you need any additional information.

Thank you for your assistance.

Best regards,
[Sathishkumar G]

[Mob: 7373349516]

[sathishtoverto@gmail.com]

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,089 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 24,531 Reputation points
    2024-07-08T13:48:28.64+00:00

    First, ensure that you have accesses to

    1. Azure DevOps Access
    2. Azure DevOps CLI or REST API
    3. Tools Installation (Azure DevOps CLI installed)

    Steps to Export Test Suites and Test Plans

    1. Export Test Plans and Test Suites using Azure DevOps REST API:
      • You will need to call the REST API to get the test plans and test suites. You can use the GET method for the following endpoints:
      • Test Plans:
        
              GET https://dev.azure.com/{organization}/{project}/_apis/test/plans/{planId}?api-version=6.0
        
        
      • Test Suites:
        
              GET https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/suites/{suiteId}?api-version=6.0
        
        
    2. Save the Exported Data:
      • Save the response data from the REST API calls into JSON files.

    Steps to Import Test Suites and Test Plans

    1. Create Test Plans and Test Suites in Target Tenant:
      • Use the saved JSON files to create test plans and test suites in the target tenant. You will need to call the REST API to create these resources.
      • Create Test Plans:
        
              POST https://dev.azure.com/{organization}/{project}/_apis/test/plans?api-version=6.0
        
        
      • Create Test Suites:
        
              POST https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/suites?api-version=6.0
        
        
    2. Populate Test Plans and Test Suites:
      • Ensure that all the necessary details from the source test plans and test suites are correctly mapped and populated in the target tenant.

    Example Scripts

    Here are example scripts for exporting and importing test plans and test suites using Azure DevOps CLI and REST API.

    Export Script (Python)

    
    import requests
    
    import json
    
    organization = 'ReposMigration'
    
    project = 'VSO Repos Migration'
    
    plan_id = 'YOUR_PLAN_ID'
    
    personal_access_token = 'YOUR_PERSONAL_ACCESS_TOKEN'
    
    # Get Test Plan
    
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/plans/{plan_id}?api-version=6.0'
    
    response = requests.get(url, auth=('', personal_access_token))
    
    test_plan = response.json()
    
    # Save Test Plan
    
    with open('test_plan.json', 'w') as file:
    
        json.dump(test_plan, file)
    
    # Get Test Suites
    
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{plan_id}/suites?api-version=6.0'
    
    response = requests.get(url, auth=('', personal_access_token))
    
    test_suites = response.json()
    
    # Save Test Suites
    
    with open('test_suites.json', 'w') as file:
    
        json.dump(test_suites, file)
    
    

    Import Script (Python)

    
    import requests
    
    import json
    
    organization = 'sathishkumarg0353'
    
    project = 'migration'
    
    personal_access_token = 'YOUR_PERSONAL_ACCESS_TOKEN'
    
    # Load Test Plan
    
    with open('test_plan.json', 'r') as file:
    
        test_plan = json.load(file)
    
    # Create Test Plan
    
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/plans?api-version=6.0'
    
    headers = {'Content-Type': 'application/json'}
    
    response = requests.post(url, headers=headers, data=json.dumps(test_plan), auth=('', personal_access_token))
    
    created_test_plan = response.json()
    
    # Load Test Suites
    
    with open('test_suites.json', 'r') as file:
    
        test_suites = json.load(file)
    
    # Create Test Suites
    
    for suite in test_suites['value']:
    
        url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{created_test_plan["id"]}/suites?api-version=6.0'
    
        response = requests.post(url, headers=headers, data=json.dumps(suite), auth=('', personal_access_token))
    
        created_test_suite = response.json()
    
        print(f'Created Test Suite: {created_test_suite["id"]}')
    

    More links :

    0 comments No comments

  2. Sathishkumar G 0 Reputation points
    2024-07-09T15:35:02.11+00:00

    we receiving below error provide the solution
    User's image

    import requests
    
    import json
    
    organization = 'ReposMigration'
    
    project = 'VSO Repos Migration'
    
    plan_id = '20397'
    
    personal_access_token = 'xxxxxxxx'
    
    # Get Test Plan
    
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/plans/{plan_id}?api-version=6.0'
    
    response = requests.get(url, auth=('', personal_access_token))
    
    test_plan = response.json()
    
    # Save Test Plan
    
    with open('test_plan.json', 'w') as file:
    
        json.dump(test_plan, file)
    
    # Get Test Suites
    
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{plan_id}/suites?api-version=6.0'
    
    response = requests.get(url, auth=('', personal_access_token))
    
    test_suites = response.json()
    
    # Save Test Suites
    
    with open('test_suites.json', 'w') as file:
    
        json.dump(test_suites, file)
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.