This blog post is about how to automate the updates of test execution statuses through the ZAPI cloud Zephyr Rest API. It covers the following aspects of continuous testing and automated execution coverage:

  • No manual intervention to update the execution status of any test within Zephyr in JIRA, which makes continuous testing easier and automated.
  • Possibility to perform automated updates from a CI Platform or a Tool Like SOAP UI/Groovy.

The Scope is limited to updates using ZAPI cloud API of Zephyr that is more complex than in the Server API case.

 Pre-requisites to use ZAPI

  1. Jira Platform Access: A JIRA Cloud Platform account is needed
  2. Zephyr Plugin Enabled: The Menu called Tests is displayed
  3. ZAPI Plugin Enabled: The API Keys are available. Those include a Secret Key and an Access Key
  4. Windows Machine/CI Platform for test executions

ZAPI 1_edited

 

Where and When to use ZAPI

This diagram clearly illustrates where and when to use ZAPI.

ZAPI 2

Some Theory About JWT (Json Web Tokens)

What is a JSON Web Token (JWT)? It is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.

JWT structure contains:

Header

{ “alg”: “HS256”, “typ”: “JWT” }

Payload (Reserved Claims, Public Claims, Private Claims where below are the 4 mandatory claims to use in JIRA/Zephyr)

{
“iss”: “jira:15489595”,
“iat”: 1386898951,
“qsh”: “8063ff4ca1e41df7bc90c8ab6d0f6207d491cf6dad7c66ea797b4614b71922e9”,
“exp”: 1386899131
}

Signature

uKqU9dTB6gKwG6jQCuXYAiMNdfNRw98Hw_IWuA5MaMo

 

About the QSH Claim

} The QSH is the signed canonical request for the URI of the API you want to call:

Payload (Reserved Claims, Public Claims and/or  Private Claims)

{
“iss”: “jira:15489595”,
“iat”: 1386898951,
“qsh”: “8063ff4ca1e41df7bc90c8ab6d0f6207d491cf6dad7c66ea797b4614b71922e9”,
“exp”: 1386899131

It is calculated as follows: (Canonical Method is: GET / PUT /POST HTTP Method)

ZAPI 3

About the iss Claim

The iss corresponds to the access token of the Zapi cloud API:

Payload (Reserved Claims, Public Claims and/or  Private Claims)

{
“iss”: “Put the value of the Access Token of ZAPI here”,
“iat”: 1386898951,
“qsh”: “8063ff4ca1e41df7bc90c8ab6d0f6207d491cf6dad7c66ea797b4614b71922e9”,
“exp”: 1386899131
}

Is gathered as follows:

ZAPI 4

About the iat and exp Claims

The iat and exp correspond to the Issued-at time and the Expiration time to frame the time where the JWT token is valid. Those Claims have the UNIX Format (the difference in seconds between the actual date and “1970/01/01 00h:00min:00s”:

Payload (Reserved Claims, Public Claims and/or  Private Claims)

{
“iss”: “Put the value of the Access Token of ZAPI here”,
“iat”: 1386898951,
“qsh”: “8063ff4ca1e41df7bc90c8ab6d0f6207d491cf6dad7c66ea797b4614b71922e9”,
“exp”: 1386899131
}

This website http://www.unixtimestamp.com/ can be useful to gather the UNIX Format manually.

 

How to gather the JWT manually (http://jwt.io)

The output is the JWT Token (in the “Encoded” field pictured below). Th inputs are Header / Payload (including the QSH) (alos pictured below).

ZAPI 5

Some Theory About JWT (How to get JWT using a script?

Step 1: Know your API. (https://prod-api.zephyr4jiracloud.com/connect/public/rest/api/1.0/execution/executionId )

In our case of updating test execution status and relying on the online help

http://docs.zfjcloud.apiary.io/#reference/execution/update-execution/update-execution

Step 2: Know the canonical method (PUT, POST or GET etc..)

Step 3: Code a function that return the QSH (Looks Like this in Autoit where the argument is the canonical request:)

ZAPI 6

Step 4: code a function that return the signature of your Json Rest Request (Looks as below):

ZAPI 7

The value of the secret key is taken from the Zephyr Menu called: API Keys

ZAVI 8

Step 5: code a function that sends a Json request (below are the expected headers):

ZAPI 9

 

Automation of Updates of Test Execution Status in Zephyr through ZAPI Cloud API

A. From a windows command line (cmd).

Step 1: Put the script and the configuration file (config_backup.ini) in a folder in your HD:  C:\UpdateStatus

Call the script Zephyr_Status_Update.exe as below:

ZAPI 9

<STATUS ID>: is equal to:

1 when Test is PASSED.

                                 2 when Test is Failed.

UPDATE or CREATE is the third argument and is used depending on the targeted use.

 

Step 2: <EXECUTION ID>: is gathered from the UI of JIRA using F12 by Spying the Test execution status Field:

ZAPI 10

Step 3: <EXECUTION ID>: is gathered from the highlighted element below:

ZAPI 11

B. From SoapUI (Using a Groovy Step) 

The Call in SOAPUI is as below:

ZAPI 12

Here is some supporting material. Note to make use of the executable file, you will need to remove the _ from the file name (from .exe_ to .exe): UpdateStatus