Test definition syntax

Information about how the test is defined as a YAML file.

The test is defined as a YAML file with the following sections:
  • configs - Displays the configuration values for the variables that are specified in the file.
  • steps - Displays the flow for the test case and runs through the list of steps in order. Each step has a common set of parameters.
The type attribute in the test definition YAML file describes the type of steps.
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
 

The following table summarizes the set of parameters supported by the type attribute.

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:
  • 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 test fails, the stoponfailattribute 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: ^[a-z]+/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"

For more information about assigning variables on a YAML configuration file, see Variable assignment in YAML configuration.