Forum Discussion

markos's avatar
markos
Occasional Contributor
8 months ago

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 example of a `curl` command. But that seems a little funny to drop to shell, when we can code inside the test suite.

  • markos's avatar
    markos
    Occasional Contributor

    I'm looking for actual code samples that work. We found it difficult to get the Python code working, due to the complex Form POST fields required for instance `folderId`.

    Maybe my question is more of a Zephyr question. I'll look in Zephyr Scale Questions 

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    Hi markos

    Definitely it is possible to automate the process of posting jUnit XML results from TestComplete to Zephyr using scripting within your TestComplete project. 


    Kindly write a script within TestComplete to handle the HTTP request to Zephyr's API directly, eliminating the need to use a separate shell command

    Write Script to Read and Post jUnit XML Results and Integrate Script with execution

    Ensure that your script handles authentication with Zephyr's API accurately

    Process the response from the API request within your script to handle any errors and confirm that the test results were successfully uploaded

     


    Hope this helps - Happy to help further !!

     


    Thank you very much and have a fantastic day!

    Warm regards

  • Humashankar's avatar
    Humashankar
    Champion Level 2

    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