Forum Discussion

markos's avatar
markos
Occasional Contributor
2 years ago
Solved

POST jUnit.xml results file to Zephyr

Can a TestComplete project be coded to automatically POST jUnit.xml results file to Zephyr after any/all tests are ran? The docs at TestComplete with Zephyr Scale | SmartBear Community show an exampl...
  • Humashankar's avatar
    2 years ago

    Hi markos  - Would you like to give a try with the below to see whether you can move on - 

    # Zephyr API endpoint (replace with your actual URL)

    zephyr_url = "https://your-zephyr-domain/api/v2/automations/executions/junit"

     

    # Authentication (replace with your Zephyr API token)

    auth_header = {"Authorization": "Token your_api_token"}

     

    # Path to your jUnit.xml file (replace with your actual path)

    junit_file_path = "path/to/your/junit.xml"

     

    # Read jUnit.xml content

    with open(junit_file_path, "r") as f:

        junit_content = f.read()

     

    # prepare form data (might require additional fields based on Zephyr version)

    form_data = {

        "xmlData": junit_content,

        "projectId": 100,  # Replace with your project ID in Zephyr

        # Add other required form fields as needed (e.g., folderId)

    }

    # Send POST request

    response = requests.post(zephyr_url, headers=auth_header, data=form_data)

    # Check for successful response

    if response.status_code == 200:

        print("jUnit results uploaded successfully!")

    else:

        print(f"Error uploading results: {response.status_code} - {response.text}")

     

    Smart Strategies

    • Import the requests library.
    • Define the Zephyr API endpoint and authentication header.
    • Read the jUnit.xml content.
    • Prepare form data with junitData (XML content) and potentially other required fields like projectId. Refer to Zephyr's API documentation for specific field requirements based on your version.
    • Send a POST request with the prepared form data and authentication header.
    • Handle the response based on the status code.

    Regards