pytestjira-zephyr

Zephyr scale server: uploading test results to Zephyr Scale via the automation API


I'm using Zepyhr Scale Server and I would like to upload to Zephyr the results of my automation testsuite made with pytest. I've tried this POST request:

post(url="https://{my-jira-host}/rest/atm/1.0/automation/execution/{projectKey}", auth=({my_username}, {my_password}), files={"file":open("test_results.zip","rb")})

but it doesn't work because the response is "errorMessages":["Invalid Custom Format JSON file"]}.

I'm uploading a zip file containing one xml file generated with

pytest --junitxml=output/junitxml_report.xml as it's explained here https://support.smartbear.com/zephyr-scale-cloud/docs/test-automation/pytest-integration.html

I've tried to make the same request with an API client (Postman) and the error is "Invalid ZIP file", even if I fail the authentication with a wrong username or even if I upload the xml file only.

Maybe someone does the same thing and could help me? I'm a newbie :) thanks!


Solution

  • I found the API documentation lacking, but I managed to enumerate many endpoints.

    I've bundled them in a nodejs lib, it won't be of use for your Python script, but the endpoints will be the same... Maybe they can help you on your way.

    https://www.npmjs.com/package/@dbouckaert/zephyr-scale-reporter

    Example: get all testcases for a project

    /**
     * This function will get all testcases for a certain project and add them to variables.testCasesArray
     * @returns {void}
     */
    export const getAllTestcases = async (): Promise<void> => {
      await request(variables.url)
        .get(`/rest/tests/1.0/project/${variables.projectId}/testcases`)
        .auth(variables.username, variables.password)
        .expect(200)
        .then((res) => {
          variables.testCasesArray = res.body.testCases;
        });
    };