Import Results using Maven Plugin for TestNG

If the automation project includes TestNG + Java (with Maven) structure, then configure the Maven dependency in the project as described below.

Working Sample

Refer to Sample Projects for Automation section for a more concrete end-to-end example.

Open the pom.xml and add the configurations as described on the Automation API screen for Maven. 

1. Use API Key for Importing Results

Please Generate API Key if you don't have an API key for the selected project. 

2. Import Results

Step 1: Add the following to the <build> -> <plugins> block in your pom.xml:

<build>
       <plugins>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <version>2.22.0</version>
          </plugin>
          <plugin>
             <groupId>com.qmetry</groupId>
             <artifactId>automation</artifactId>
             <version>2.0.6</version>
             <executions>
                <execution>
                   <phase>test</phase>
                   <goals>
                      <goal>TestngFileUpload</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>

Please refer to View Import Results using the REST API section to view all possible request parameters. 

Step 2: Add the following to the <pluginRepositories> block in pom.xml like:

<pluginRepositories>
       <pluginRepository>
          <id>qmetrytestmanager-mvn-repo</id>
          <name>QMetry Test Manager Maven Repository</name>
          <url>https://raw.github.com/qmetry/qtm4j-maven-uploader/mvn-repo/</url>
          <releases>
             <enabled>true</enabled>
             <updatePolicy>always</updatePolicy>
          </releases>
       </pluginRepository>
</pluginRepositories>

Step 3: Add qmetry.properties file to root directory of your project. Download the sample file.

Configure below properties: 

Authorization: (automation.qmetry.authorization)

Maven automation is protected by the restrictions provided by JIRA. You need to log in to Jira using the "automation.qmetry.authorization" parameter. Follow the below steps to generate basic Auth and pass it to the qmetry.properties:

  1. Build a string of the form username:password
  2. Encode the string in Base64 format.
  3. Pass an "Authorization" parameter with content "Basic " followed by the encoded string. For example, the string "fred:fred" encodes to "ZnJlZDpmcmVk" in base64, so you would make the request as follows.
 automation.qmetry.authorization=Basic YWRtaW46YWRtaW4=
    automation.qmetry.enabled = true
    automation.qmetry.debug = true
    automation.qmetry.url= http://qtm4j-qa-postgres-datacenter.qmetry.com/rest/qtm4j/automation/latest/importresult 
    automation.qmetry.apikey = 88a7f1da08c39486b3c7e33cff200a11154d9f3705612c99192802dac8fde1421dbf79719b9f3b73dea090797210
    automation.qmetry.filepath= target/testng.xml
    automation.qmetry.environment=env
    automation.qmetry.build=build
    automation.qmetry.attachfile=true
    automation.qmetry.testCycleToReuse=NR-TR-1
	automation.qmetry.testcycle.summary=Test Cycle summary
    automation.qmetry.testcycle.labels=l1,l2,l3
    automation.qmetry.testcycle.components=c1,c2,c3
    automation.qmetry.testcycle.priority=High
    automation.qmetry.testcycle.status=To Do
    automation.qmetry.testcycle.sprintId=1242
    automation.qmetry.testcycle.fixVersionId=14234
    automation.qmetry.testcycle.description=Test Cycle description
    automation.qmetry.testcycle.assignee={Valid User Account Key}
    automation.qmetry.testcycle.reporter={Valid User Account Key}
    automation.qmetry.testcycle.plannedStartDate=15/May/2020 00:00
    automation.qmetry.testcycle.plannedEndDate=30/May/2020 00:00
    automation.qmetry.testcycle.customFields=[{"name" : "custom field 1", "value": "high,medium,low"},{"name" : "custom field 2", "value": "29/May/2020"}]
    automation.qmetry.testcase.labels=l1,l2,l3
    automation.qmetry.testcase.components=c1,c2
    automation.qmetry.testcase.priority=Medium
    automation.qmetry.testcase.status=In Progress
    automation.qmetry.testcase.sprintId=34534
    automation.qmetry.testcase.fixVersionId=35345
    automation.qmetry.testcase.description=Test Case description
    automation.qmetry.testcase.assignee={Valid User Account Key}
    automation.qmetry.testcase.reporter={Valid User Account Key}
    automation.qmetry.testcase.estimatedTime=10:10
    automation.qmetry.testcase.customFields=[{"name" : "custom field 1", "value": "high,medium,low"},{"name" : "custom field 2", "value": 10.12}]
    automation.qmetry.authorization=Basic YWRtaW46YWRtaW4=

Once the file is configured, the automation test results will get uploaded automatically whenever the user executes the automation project (e.g. using ‘mvn test’).


As an alternate of Step 3, you can also set properties with the following command with command line arguments. You can also pass multiple command-line arguments.

mvn clean test "-Dautomation.qmetry.testcycle.summary={{Test Cycle Summary}}" "-Dautomation.qmetry.testcycle.labels=lbl1,lbl2,lbl3"

3. View imported test results

Please refer to the View Imported Test Results section to view imported test results.