3 About BDD Operators

Learn about the different operators in Oracle Communications Solution Test Automation Platform (STAP).

An Operator is a function that takes arguments and returns the result of operation as Passed or Failed. Behavior-Driven Development (BDD) operators are used in Validation section of the Test Step.

String Operators

BDD String Operators use string text as an argument.

The following are the string operators used in BDD:

  • STRING_EQUALS
  • STARTS_WITH
  • ENDS_WITH
  • CONTAINS
  • MATCHES

Note:

By default (without mentioning operator), BDD uses String Equals as the operator.

BDD Example:

The following example shows how to use a string operator in STAP BDD:

First, set up the variables:

Save:
| planType | Premium |
| emailID | JohnDoe@bills.com |
| errorLog | Connection Timeout |
| name | John Doe |
| connectionStatus | Active |
| smsContent | Your Bill Number is 1 |
| billEnd | John Doe Your Bill Number is 1 |

The following commands get the response, which contains various variables.

Data:
| id | getbill |

The following validation will be successful, given the values set above.

| $status | 200 |
| planType | Premium |
| errorLog | %STARTS_WITH(Connection) |
| name | %ENDS_WITH(Doe) |
| smsContent | %CONTAINS(Bill Number) |
| billEnd | %CONCAT(${name}, ${smsContent}) |
| emailID | %MATCHES((.*)@(.*)) |

Runtime BDD:

The following is the runtime BDD response for the string operator:

Then get mock response, validating bill details
Data:
#|  Property  |  Value    |  Runtime Value  | 
 |  id        |  getbill  |  getbill        | 
Validate:
#|  Property         |  Value                                       |  Property Value                  |  Runtime Value                   |  Result  | 
 |  $status          |  200                                         |  200                             |  SUCCESS                         |  PASSED  |  
 |  planType         |  Premium                                     |  Premium                         |  Premium                         |  PASSED  | 
 |  errorLog         |  %STARTS_WITH(Connection)                    |  Connection Timeout              |  Connection Timeout              |  PASSED  | 
 |  name             |  %ENDS_WITH(Doe)                             |  John Doe                        |  John Doe                        |  PASSED  | 
 |  smsContent       |  %CONTAINS(Bill Number)                      |  Your Bill Number is 1           |  Your Bill Number is 1           |  PASSED  | 
 |  billEnd          |  %CONCAT(${name}, ${smsContent})             |  John Doe Your Bill Number is 1  |  John Doe Your Bill Number is 1  |  PASSED  | 
 |  emailID          |  %MATCHES((.*)@(.*))                         |  JohnDoe@bills.com               |  JohnDoe@bills.com               |  PASSED  |

Numeric Operators

Numeric operators use numbers as arguments, such as integer, double, big integer, big double, or a saved variable representing these numbers.

Instead of spelled out numeric operators, you have the option to use symbol-based operators.

Table 3-1 lists the numeric operators.

Table 3-1 Operator Symbols

Symbol Text BDD Example Numeric Example
== %EQUALS()

==${amount}

==20.50

123==123

12.45==12.4

12 == 12.0

!= %NOT_EQUAL()

!=${value}

!=24

123 != 321

12.34 != 12.3456

> %GREATER_THAN()

>123

>${value}

123>120

123.0 > 120

123 > 120.0

< %LESS_THAN()

<123

< ${value}

120 < 123

120.0 < 123

120 < 123.0

>= %GREATER_THAN_OR_EQUAL

>=123

>=${value}

123>=120

123.0 >=120

123 >=120.0

<= %LESS_THAN_OR_EQUAL

<=123

<=${value}

120 <=123

120 <=123.0

120.0 <=123

BDD Example:

The following example shows how to use a numeric operator in STAP BDD:

First, set up variables:

Save:
| billAmount | 2000 |
| discount | 10 |
| transactionId | 5 |
| creditScore | 400 |
| subscriptionFee | 200 |

The following commands get the response, which contains various variables.

Data:
| id | getbill |
 
Validate:
| $status | 200 |
| billAmount | == 2000 |
| discount | %EQUAL(10) |
| transactionId | != 1 |
| subscriptionFee | %NOT_EQUAL(0) |
| creditScore | > 200 |
| billAmount | %GREATER_THAN(1500) |
| discount | < 12 |
| transactionId | %LESS_THAN(6) |
| creditScore | %GREATER_THAN_OR_EQUAL(${subscriptionFee}) |
| billAmount | >=2000 | 
| discount | %LESS_THAN_OR_EQUAL(10) |
| subscriptionFee | <= ${creditScore} |

The following commands get the response, which validates the bill details:

Then get mock response, validating bill details
Data:
#|  Property  |  Value    |  Runtime Value  | 
 |  id        |  getbill  |  getbill        | 
Validate:
#|  Property         |  Value                                       |  Property Value                  |  Runtime Value                   |  Result  | 
 |  $status          |  200                                         |  200                             |  SUCCESS                         |  PASSED  | 
 |  billAmount       |  == 2000                                     |  2000                            |  2000                            |  PASSED  | 
 |  discount         |  %EQUAL(10)                                  |  10                              |  10                              |  PASSED  | 
 |  transactionId    |  != 1                                        |  5                               |  5                               |  PASSED  | 
 |  subscriptionFee  |  %NOT_EQUAL(0)                               |  200                             |  200                             |  PASSED  | 
 |  creditScore      |  > 200                                       |  400                             |  400                             |  PASSED  | 
 |  billAmount       |  %GREATER_THAN(1500)                         |  2000                            |  2000                            |  PASSED  | 
 |  discount         |  < 12                                        |  10                              |  10                              |  PASSED  | 
 |  transactionId    |  %LESS_THAN(6)                               |  5                               |  5                               |  PASSED  | 
 |  creditScore      |  %GREATER_THAN_OR_EQUAL(${subscriptionFee})  |  400                             |  400                             |  PASSED  | 
 |  billAmount       |  >=2000                                      |  2000                            |  2000                            |  PASSED  | 
 |  discount         |  %LESS_THAN_OR_EQUAL(10)                     |  10                              |  10                              |  PASSED  | 
 |  subscriptionFee  |  <= ${creditScore}                           |  200                             |  200                             |  PASSED  |

Array Operators

Array operators are BDD validation operators used to compare the contents of two arrays. Typically, one array is returned by the system under test in a JSON or XML payload, while the other is stored in a STAP variable. Each array operator evaluates the comparison between the two arrays and returns a result of passed or failed. This allows you to validate whether the response data matches the expected array exactly, partially matches it, or contains specific expected elements.

General Array Operators

The following operators compare elements in two arrays. To match, the elements must both either be inside quotation marks or both be without them.

If you set the following data:

Save:
| $ARRAY{bills1} | 25.213 |
| $ARRAY{bills1} | 30.456 |
| $ARRAY{bills1} | "Bill is complete." |

And then you get the response (which contains an array variable called bills):

Data:
| id | getdata |
  • The ARRAY_COMPARE operator can compare the bills array from the returned JSON data to the bills1 array created above:

    Validate:

    | bills | %ARRAY_COMPARE($ARRAY{bills1}) |

    Validation will succeed only if the bills array contains the following values in the following order:

    "bills": [25.213, 30.456, "Bill is complete."]
  • The ARRAY_COMPARE_IGNORE_ORDER operator can compare the bills array from the returned JSON data to the bills1 array created above:

    Validate:

    | bills | %ARRAY_COMPARE_IGNORE_ORDER($ARRAY{bills1}) |

    Validation will succeed if the bills array contains the following values in any order. For example, the following array will pass validation:

    "bills": [30.456, 25.213, "Bill is complete."]
  • The ARRAY_IN operator can compare the bills array from the returned JSON data to the bills1 array created above:

    Validate:

    | bills | %ARRAY_IN($ARRAY{bills1}) |

    Validation will succeed if the bills array contains any selection of elements matching those in the bills1 array, in any order. For example, the following array will pass validation:

    "bills": [30.456, 25.213]

Array Operators for Quoted Strings

If you set the following data:

Save:
| $ARRAY{products1} | "5G Lite Data Service" |
| $ARRAY{products1} | "5G Basic Data Service" |
| $ARRAY{products1} | "123456" |
| $ARRAY{products1} | "Wireless Bundle" |

And then you get the response (which contains an array variable called products):

Data:
| id | getdata |
  • The ARRAY_COMPARE_IGNORE_QUOTES operator can compare the products array from the returned JSON data to the products1 array created above:
  • The ARRAY_COMPARE_IGNORE_ORDER_QUOTES operator can compare the products array from the returned JSON data to the products1 array created above:

    Validate:

    | products | %ARRAY_COMPARE_IGNORE_ORDER_QUOTES($ARRAY{products1}) |

    Validation will succeed if the products array contains the following values in any order, even though some of the values are not enclosed in quotes. For example, the following array will pass validation:

    "products": [123456, "5G Basic Data Service", "5G Lite Data Service", "Wireless Bundle"]

  • The ARRAY_IN_IGNORE_QUOTES operator can compare the products array from the returned JSON data to the products1 array created above:

    Validate:

    | products | %ARRAY_IN_IGNORE_QUOTES($ARRAY{products1}) |

    Validation will succeed if the products array contains any selection of elements matching those in the products1 array, in any order, even though some of the values are not enclosed in quotes. For example, the following array will pass validation:

    "products": [123456, "5G Lite Data Service"]
  • (Release 1.25.1.1.0 or later) The ARRAY_IN_IGNORE_ORDER_QUOTES operator can compare the products array from the returned JSON data to the products1 array created above:

    Validate:

    | products | %ARRAY_IN_IGNORE_ORDER_QUOTES($ARRAY{products1}) |

    Validation will succeed if the products array contains any selection of elements matching those in the products1 array, in any order, even though some of the values are not enclosed in quotes, and disregarding empty strings. For example, the following array will pass validation:

    "products": [123456, "5G Basic Data Service", ""]

Array Utility Functions

The ARRAY_UNIQUE can derive a new array that contains only unique values from an input array. Any duplicate values present in the source array are removed.

This function is useful when response data may contain duplicate entries but validation must be performed against a distinct set of elements.

If you set the following data:

Save: 
| $ARRAY{products3} | "5G Basic Data Service" | 
| $ARRAY{products3} | "5G Lite Data Service" | 
| $ARRAY{productListWithDup} | "5G Basic Data Service" | 
| $ARRAY{productListWithDup} | "5G Basic Data Service" | 
| $ARRAY{productListWithDup} | "5G Lite Data Service" | 
| productListUniq | %ARRAY_UNIQUE($ARRAY{productListWithDup}) | 

In this example:

  • productListWithDup contains duplicate product values.

  • productListUniq stores the result of the ARRAY_UNIQUE function, which removes duplicate entries and retains only unique values.

When you run a mock action and read the task data:

| $request | $arraydata | 

You can validate the response using the following validations:

Validate: 
| services[0].products[*].name | %ARRAY_COMPARE_IGNORE_ORDER_QUOTES($ARRAY{products3}) | 
| services[0].products[*].name | %ARRAY_COMPARE_IGNORE_ORDER_QUOTES($ARRAY{productListUniq}) | 

Validation will succeed if the services[0].products[*].name array in the response contains the same unique product values as productListUniq, regardless of order and quotation differences.

This ensures that duplicate values in the response do not cause validation failures when only the presence of unique elements is required.

Logical Operators

Logical operators help you define and evaluate multiple conditions in BDD scenarios. Use these operators to create flexible, condition-based expressions.

Using %EVAL_CONDITION()

The %EVAL_CONDITION() function evaluates logical expressions using operators, such as AND, OR, and NOT. Use this function in the validation step to handle complex conditions.

Syntax

%EVAL_CONDITION((condition1) OPERATOR (condition2))

You can use the following operators:

  • AND: Returns true if both conditions are true.
  • OR: Returns true if at least one condition is true.
  • NOT: Returns true if the condition is false.

Examples:

  • AND Operator

    Validates if both conditions are satisfied.

    | age | %EVAL_CONDITION((>10) AND (<40)) |
  • OR Operator

    Validates if either condition is satisfied.

    | category | %EVAL_CONDITION((Platinum) OR (Gold)) |
  • NOT Operator

    Validates if the condition is not satisfied.

    | category | %EVAL_CONDITION(NOT(Regular)) |
  • Combining Operators

    Validates using a combination of AND, OR, and NOT.

    When combining operators (AND, OR, NOT), it is important to understand their order of precedence:
    • NOT is evaluated first.
    • AND is evaluated next.
    • OR is evaluated last.

    Parentheses () can be used to group conditions and explicitly control the evaluation order.

    | category | %EVAL_CONDITION(((Platinum) OR (Gold)) AND (NOT(Regular))) |

Using %IF_ELSE()

Use `%IF_ELSE()` during the save operation. This function saves one of two values based on a specified condition.

Syntax:

`%IF_ELSE(condition, valueIfTrue, valueIfFalse)`

Example:

Save _subscription.id as id if status is Active; otherwise, save error.

| _subscription.id | %IF_ELSE(status==Active, id, error) |

Example Scenario:

The following sample demonstrates using these logical operators in a BDD workflow for subscription management.

Case: Operators 

When set variable, for default values
Save:
| subscriber.name | John Doe | 
| subscriber.category	| Platinum	|
| subscriber.type	| Residential	|
| subscriber.age	| 30 |
| subscriber.address	| 2685 California Street |
| subscriber.state	| CA |
| subscriber.city	| Mountain View |
| subscriber.country	| USA	|
| subscriber.code	| 94040	|
| subscriber.emailId	| john.doe@domain.com |
| subscriber.mobile	| 9876543211 |
| plan.name | 5GBasic |
| payment.mode | Cash |
| bill.expectedTotalAmount | 3 |
| payment.mode | Cash |
| payment.amount | 3 |
| payment.paidAt | KIOSK |
| bill.totalTax | 0 |

When create a new subscription, in the billing system
Data:
| name | ${subscriber.name} |
|	category | ${subscriber.category}	|
|	type	| ${subscriber.type}	|
|	age	|	${subscriber.age} |
|	address	| ${subscriber.address}	|
|	state	| ${subscriber.state}	|
|	city	| ${subscriber.city} |
|	country	| ${subscriber.country}	|
|	code	| ${subscriber.code}	|
|	emailId	| ${subscriber.emailId} |
|	mobile	| ${subscriber.mobile} |
Validate:
| $status | %EVAL_CONDITION((201) OR (200)) |
| category | %EVAL_CONDITION((Platinum) OR (Gold)) |
| age | %EVAL_CONDITION((>10) AND (<40)) |
| category | %EVAL_CONDITION(((Platinum) OR (Gold)) AND (NOT(Regular)) ) | 

Save:
| _subscription.id   | %IF_ELSE(status==Active,id,error) |
| accStatus | status |

Then read subscription
RepeatUntil: 
| ${accStatus} | %EVAL_CONDITION((Active) OR (Ready)) |
| $startAfter | 1 |
| $interval  | 1 |
| $endAfter | 5 |
Data:
| id | ${_subscription.id} |
Validate:
| $status | 200   |
Save:
| accStatus | status |