Skip to main content

Logical Test Components

Logical components are a type of component that you can add to a test using the Compose tab (aka Composer). To learn how to access the components and create a test using the Composer see Writing API Tests with the Composer.

Logical Components

What You'll Need

Logical Components

Each

Allows you to iterate over a collection of elements and execute the piece of code for each element.

Parameters
Fields
Expression

| REQUIRED | EXPRESSION |

The path of the collection you want to iterate on.


Examples1each.png

The for each 'legs' collection checks if vector item is an integer value.

If a collection is nested in another one, you need to refer to them as _1, _2, and so on.

nestedEach.png

The for each payload.content.flights collection checks if price.amount is an integer. Then, the for each legs array, a nested collection within the flights collection, checks if vector item is an integer value.

Code View Examples
- id: each
children:
- id: assert-is
expression: vector
type: integer
expression: payload.legs

If

Allows you to run a specific piece of code only if a specific condition is met.

Parameters
Fields

| REQUIRED | EXPRESSION |

The path of the collection you want to iterate on.


Examples

If payload.success is equal to true then the code within the element is executed, otherwise is skipped.

if.png

If _1.intermediate exists then the code within the element is executed, otherwise is skipped. This is useful when the element is not always present.

ifexists.png
Code View Examples
- id: if
children:
- id: assert-equals
expression: payload.message
value: Seats Available
- id: assert-equals
expression: payload.content.flightid
value: ${id}
type: string
expression: payload.success == true

While

Allows you to run a block of assertions as long as a condition is valid.

Parameters
Fields
Expression

| REQUIRED | EXPRESSION |

The condition that has to be met for the assertions block to be executed.


Examples
while.png
Code View Examples
- id: while
children:
- id: comment
text: Executes assertion until items are less than 5
expression: items<5