Our former SoapUI learning modules served as an introduction to SoapUI and its programming foundations. Consequently, we’ll be delving into higher-level Groovy scripting principles. Let’s initially cover Conditional flow statements – comprising both Boolean and iterative declarations. Afterwards, we’ll focus on arrays collection.
This marks the ninth module in our SoapUI instruction series.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
Conditional declarations are employed to control the progress of execution. Groovy accommodates numerous kinds of conditional statements.
What You Will Learn:
#1. Control or logical statements:
These proclamations result in true or false depending on logical conditions. They consist of AND, OR, and NOT operations. The symbols used are ‘&& (and)’, ‘|’ (or), and ‘! (exclamation)’ respectively. Their behavior is clarified in the truth table:
“And” Operator truth table:
“OR” operator truth table:
“NOT” operator for negation purpose
Conditional statement: programming languages support the subsequent conditional statements:
- If…else declaration
- If…else if…else proclamation
- Ternary operator
- Switch declaration
A) if…else block structure:
if <condition>
{
<Statements to be executed>
}
Else
{
<default declarations>
}
In this structure, once <condition> returns true, the appropriate declaration will be executed. Any block with more than one row should be enclosed with curly braces. That directs the whole block to execute based on the condition.
Consider the example code snippet.
int a=100 int b=200 if (a>b) { log.info('B surpasses A'); <To Do> } else { log.info('A is superior or both are equal'); <To Do> }
An if…else… statement should contain just one ELSE block.
B) Multiple conditional blocks: if…else if…else syntax
if <condition1>
{
<Statements to be executed>
}
Else if <condition2….n>
{
<Statements to be executed>
}
Else
{
<default declarations>
}
The If…else if…else statement is marginally different from the if…else… statement – in that it holds an else if block. This block is utilized for including multiple conditions. Consider the following example.
int a=100 int b=200 int c=300 if (a>b && a>c) { log.info('A exceeds B and C'); } else if (b>a && b>c) { log.info('B surpasses A and C'); } else { log.info('C is greater than A and B or All have equal numerals'); }
Now observe the output screenshot for the preceding script: Also, use this as a reference for the boolean operator example:
C) Ternary operator:
This operator operates similarly to the if…else statement. It incorporates two operands such as question mark for TRUE situations and colon for FALSE / default declarations.
def A = 100
def B = (A > 100) ? “PASS” : “FAIL”
log.info(B)
Here’s the screenshot for the preceding script.
D) Switch case: This statement allows multiple conditional branches with varying values. It also supports comparison of class objects references, regular expressions, collections like arrays, lists, etc.
Switch <value>
{
case <match1>:
<execute block>;