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 used to compare two arrays. The array operators are:
  • General Array Operators
  • Array Operators for Quoted Strings

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", ""]