Import Results using Rest API

Import Results using Rest API

Working Sample

Please look at Sample Projects and Code Snippets sections for a more concrete end-to-end example.

1. Use API Key for Importing Results

Please Generate API Key if you don't have for your selected project. 

2. Import test results

Import process is divided into 2 parts. 

  1. Get Upload file URL 

  2. Upload your test result file to generated URL

2.1 Get Upload file URL 

URL : {{JIRA Base URL}}/rest/qtm/latest/automation/importresults

Method : POST

Notes

  • zip file must contain files of same format given in the 'format' param.

  • Request must be contains form-data, json raw body payload is not supported.



Authorization

This Automation REST API is protected by the same restrictions which are provided via JIRA. This means that you need to log in in JIRA to access this API.

Option 1:

To supply basic Auth header, perform the following steps:

1. Build a string of the form username:password

Password: Password refers to the API token generated from the API Token Authentication for Jira app.



1. Install the API Token Authentication for Jira app in Jira.

2. Go to Administration > User Management.

3. Locate the API Token Authentication option on the navigation bar and generate the API Token. Use this API Token as a password. 



2. Encode the string in Base64 format.

3. Supply an "Authorization" header 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.

Authorization: Basic ZnJlZDpmcmVk



Option 2:

Note: This option will be applicable only from QTM4J v4.1.9.1 onwards.

To use personal access token, perform the following steps:

  1. Go to User Profile.

  2. Click on Personal Access Tokens and click on Create token.

  3. Supply an "Authorization" header with content "Bearer" followed by generated token. 

Authorization: Bearer NTE1NTYzMTg4MDEzOit5OlIjghTQQEH/YZ7HNrpSxvcU

Request Parameters

Parameter

Type

Required

Description

Parameter

Type

Required

Description

apiKey

string

Yes

Your API Key. API Key is unique for a specific user in a single project. The result will be imported for the project associated with the given API Key.

format

string

Yes

Format of result file to be imported. Supported formats:

testAssetHierarchy

string

No

Level of Hierarchy : Test Scenario-Test Case Or Test Case-Test Step

testCaseUpdateLevel

number

No

Test Case update level while reusing test case, starts from 0 to 2. (This is only applicable when you use TestCase-TestStep Hierarchy option)

0 Append test steps while reusing Test Case.
1 Override test steps while reusing Test Case.
2 No change in test steps while reusing Test Case.
Default :- No change in test steps while reusing Test Case.

testRunName

string

No

Name of the test run to be created. Default value: Test Run

platform

string

No

Name of Platform on which test run to be executed.

labels

string

No

Comma separated names of Labels to be added to the test run.

versions

string

No

Comma separated names of versions to be added to the test run.

components

string

No

Comma separated names of Components to be added to the test run.

sprint

string

No

Name of Sprint to be added to the test run.

comment

string

No

Comment to be added to the test run.

testRunKey

string

No

Provide Test Run key to append new results to existing Test Run.

attachFile

boolean

No

Pass true for attachments upload in execution. Default value: false.

JIRAFields

JSON

No

Check specific Automation custom fields possible value and format here.



Responses

Response

Description

Response

Description

Pass

Returned if results file is uploaded successfully. The import process might take a while and you would be notified (by email or checking the status of the created test run) once the process completed.

Example

{

  "testRunURL": "{{JIRA Base URL}}/browse/JQ-1",
"testRunKey": "JQ-1"   
}



 
Fail

                                  

Returned if any validation fails

Example

{
"error": {
"errorMessage": "apiKey field is required",
"errorCode": 404
},
"success": false
}

Produces

  • application/json

3. View imported test results

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



4. JIRA Fields



i) How to get Custom Field ID?

Rest call to JIRA to get all JIRA fields.

The following URL gives all custom fields get ID for selected custom fields that you want to apply.

<Jira_Base_URL>/rest/api/2/field 



ii) Base format for custom fields.

[ { "testRun": [ { } ] }, { "testScenario": [ { } ] }, { "testCase": [ { } ] } ]



iii) Standard Custom Field Types

The following types are for reference only, other types of Custom Field Types are also supported.



Custom Field Type

Validation Rule

Example

Custom Field Type

Validation Rule

Example

Checkboxes

The checkbox accepts comma separated multiple values

{
  "customfield_10200": [
    {
      "value": "true"
    },
    {
      "value": "false"
    }
  ]
}

Date Picker

The Date picker accepts only specified format Date

{
  "customfield_10202":"2017-09-06"
}

Date Time Picker

The Date time picker accepts only specified format Date and time

{
  "customfield_10203": "2013-03-01T00:00:00.000+0400"
}

Number Field

The Number field accepts any number with decimal

{
  "customfield_10205": 2876784
}

Radio Buttons

The radio button accepts single value from JIRA fields

{
  "customfield_10206": {
    "value": "option1"
  }
}

Select List (multiple choices)

The Select List Multiple accepts comma separated multiple values

{
  "customfield_10208": [
    {
      "value": "Select List Multiple 1"
    },
    {
      "value": "Select List Multiple 2"
    }
  ]
}

Select List (single choice)

The radio button accepts single value from JIRA fields

{
  "customfield_10209": {
    "value": "Select List single 1"
  }
}

Text Field (multi-line)

It accepts text in multiple lines

{
  "customfield_10210": "this is sample.\nexample"
}

Text Field (single line)

It accepts text in single line

{
  "customfield_10211": "this is sample.example"
}

URL Field

It accepts Web URL

{
  "customfield_10212": "http://www.url-encode-decode.com/"
}

User Picker (single user)

The User field accepts only available JIRA users

{
  "customfield_10213": {
    "name": "admin"
  }
}



iv) JSON Example

If you want to set 2 custom fields (checkbox, single text) on test run issue type and one custom fields (Radio Button) on scenario and test case level.

"JIRAFields": [ { "testRun": [ { "customfield_10200": [ { "value": "true" }, { "value": "false" } ] }, { "customfield_10211": "this is sample.example" } ] }, { "testScenario": [ { "customfield_10206": { "value": "option1" } } ] }, { "testCase": [ { "customfield_10206": { "value": "option1" } } ] } ]