Test definition syntax

The test is defined as a YAML file with the following sections:

 requirements: {}

info: 
  title: "New Configuration YAML File"
  version: 2

configs:
  globalVariables:
    protocol: https://
    domain: sample-api.us-east-a.apiconnect.automation.ibm.com
    basePath: /bank
  
  inputs:
    - default:
        value: string
        type: array
    - second:
        value: number
        type: string

  steps:
    - type: request
      method: get
      url: "{{ configs.globalVariables.protocol }}{{ domain }}{{ globalVariables.basePath }}/branches"
      var: branches
      mode: json
    
    - type: assert-is
      expression: branches
      value: "{{ type }}"
    
    - type: assert-exists 
      expression: branches.[1]
      stoponfail: true
    
    - type: assert-is 
      expression: branches.[0].type
      value: string
      stoponfail: true    
    
    - type: assert-is 
      expression: branches.[0].address.city
      value: string
      stoponfail: true  
    
    - type: assert-compares 
      expression1: branches.[0].type
      expression2: branches.[7].type  
    
    - type: request
      method: get
      url: https://sample-api.us-east-a.apiconnect.automation.ibm.com/orders/order/AB1234
      var: payload
      mode: json
    
    - type: assert-equals 
      expression: payload_response_statusCode
      value: 200
      ifexists: false
      stoponfail: false
    
    - type: assert-equals 
      expression: payload_response_header_Content-Type
      value: application/json
    
    - type: assert-in 
      expression: payload_response_header_Content-Type
      values: 
        - application/json
        - application/swagger+yaml
    
    - type: assert-contains 
      expression: payload_response_header_Content-Type
      value: app
    
    - type: assert-matches 
      expression: payload_response_header_Content-Type
      value: ^[a-z]+/json
    
    - type: assert-exists 
      expression: "payload"  
      stoponfail: false
    
    - type: assert-is 
      expression: "payload.tracking_reference"
      value: "string"
      ifexists: "false" 
      stoponfail: false
    
    - type: assert-exists 
      expression: payload.shipped_at
      stoponfail: false
    
    - type: assert-exists 
      expression: payload.status
      stoponfail: false
    
    - type: assert-exists 
      expression: payload.created_at  
      stoponfail: false



Table 1. Summary of the parameters supported by the type attribute
Parameters Description Sub-attributes
globalVariables Global variables are settings that remain consistent across the entire test and typically do not change between runs. You can define any attributes here based on your requirements. For example:
- portocol: Specifies the protocol (for example, https://) used in all requests, ensuring secure communication.
- domain: Specifies the primary server address for API requests.
- basepath: Defines the base path for all API endpoints (for example, /bank), which is appended to the domain for constructing request URLs.
inputs Defines various sets of input parameters used across multiple test scenarios. You can create multiple data sets with any attributes needed for specific test scenarios. For example, default and second are two data sets, each with its own attributes tailored for different scenarios. Note: At least one data set must be present to run the test.
request Make an HTTP request. - method: Defines the HTTP method to use.
- url: Defines the URL to make the request to.
- params: Defines the key value mapping of parameters to send.
- headers: Defines the key value mapping of headers to send.
- var: Defines the name of the variable to store the response in.
- mode: Defines what type of data to expect and how to parse it (supported: json).

For example:
- type: request
- method: get
- url: https://sample-api.us-east-a.apiconnect.automation.ibm.com/bank/branches
- var: branches
- mode: json
assert-is Assert that the type of variable from the response is value. - expression: Defines the variable to test.
- value: Defines the type we expect in response.

For example:
- type: assert-is
expression: branches
value: array
assert-exists Assert that a particular variable specified in expression exists. - expression: Defines the variable to test.
- stoponfail: If one of the tests fails, the stoponfail attribute stops the execution of the remaining tests. For this, stoponfail must be set to true.

For example:
- type: assert-exists
expression: branches.[1]
stoponfail: true
assert-equals Assert that a variable is equal to value. - expression: Defines the variable to test.
- value: Defines the value to compare against.

For example:
- type: assert-equals
expression: payload_response_header_Content-Type
value: application/json
assert-greater Assert that the variable is greater than value. - expression: Defines the variable to test.
- value: Defines the value to compare against.

For example:
- type: assert-greater
expression: payload_temperature
value: application/json
assert-less Assert that the variable is lesser than value. - expression: Defines the variable to test.
- value: Defines the value to compare against.

For example:
- type: assert-less
expression: payload_temperature
value: application/json
assert-in Assert that the element identified by a given expression matches at least one item from a given list. - expression: Defines the variable to test.
- value: Defines an array of values to compare against.

For example:
- type: assert-in
expression: payload_response_status
value: application/json
assert-matches Assert that the value of the element identified by a given expression matches a specified format. - expression: Defines the variable to test.
- value: Defines the regex value to compare against.

For example:
- type: assert-matches
expression: payload_response_header_Content-Type
value: [1]+/json
assert-compares Assert that two elements are equivalent in some way. - expression1: Defines the path to the first element for comparison.
- expression2: Defines the path to the second element for comparison.

For example:
- type: assert-compares
expression1: branches.[0].type
expression2: branches.[7].type
assert-contains Assert that the value of the element identified by a given expression contains a specific substring. - expression: Defines the variable to test.
- value: Defines the substring to compare against.

For example:
- type: assert-contains
expression: payload_response_header_Content-Type
value: app
each Loop over the array referenced in the expression carrying out the sub-steps for each item found. - expression: Defines the variable to test.

For example:
- type: each
expression: "analytics.events"

  1. a-z ↩︎