Description
The IfThenElseGen Generator evaluates a Boolean-referenced value and selects one of two referenced values based on the True or False result. This generator can execute one of two outcomes based on whether the condition evaluates true/false.
- if attribute1 then
- attribute2
- else
- attribute3
in detail:
- if (ifCondition) then
- thenCondition
- else
- elseCondition
Note: The IfThenElseGen Generator allows you to define one if-then-else condition. Another generator may be needed for multiple conditions. Examples include the EvalCaseActionGen, CaseActionGen, or SwitchGen.
In This Article
- Generator Parameters
- Example 1 - Check if the User is Above 18
- Example 2 - Check if the First Name is Greater Than 8 Characters
Generator Parameters
The following parameters may be configured for the IfThenElseGen Generator. Items with an asterisk* are required.
- ifCondition* - The value of the ifCondition that should evaluated to a Boolean (true or false).
- thenCondition* - The value of the thenCondition that will be returned when the ifCondition is true.
- elseCondition* - The value of the elseCondition that will be returned when the ifCondition is false.
Example 1 - Check if the User is Above 18
A tester wants to check if a user is over 18 to ensure they can use an online platform. When under 18, the generated output should be 'Deny Access.' The generated output for users aged 18 or over should be 'Grant Access.'
If (age >= 18)
then generate 'Grant Access'
else generate 'Deny Access'
Note: This example uses three linked generators, but you can reference another attribute for the required values.
RandomGen
Generates the user's age between 0 and 120. Click here to learn more about RandomGen.
EvalGen
Determines if the user is 18 or over and returns 'true' when the condition is met.
- equation - var1 >= 18
- var1 - references the RandomGen for the user's age
IfThenElseGen
Generates 'Grant Access' or 'Deny Access' based on the user's age:
- ifCondition - references EvalGen, which generates a 'true' or 'false' value
- thenCondition - if true, generates 'Grant Access'
- elseCondition - if false, generates 'Deny Access'
Sample Output
The last column in the image below will be the generated output in this example.
- gen1 - generates user ages
- gen2 - checks if a user's age is greater than or equal to 18
- gen3 - generates 'Grant Access' or 'Deny Access' as actual output
Example 2 - Check if the First Name is Greater Than 8 Characters
A tester wants to check if a user's first name is greater than 8 characters, as 8 is the upper limit for entry. If the first name is greater than 8 characters, then the generated output should be 'Invalid.' Otherwise, it should output the first name.
if (firstName > 8)
then generate 'Invalid'
else generate 'first name value'
Note: This example uses four linked generators, but you can reference another attribute for the required values.
NameGen
Generates a capitalized first name. Click here to learn more about the NameGen.
StringLengthGen
References the NameGen (gen1) to obtain the string and determine the number of characters.
EvalGen
References the StrenthLengthGen (gen2) value to determine if the string is greater than 8 characters and returns 'true' or 'false.'
IfThenElseGen
The condition parameter references the EvalGen (gen3) generator. If true, then it generates 'Invalid.'
Otherwise, it generates the user's first name by referencing the NameGen (gen1).
Sample Output
The records with arrows are invalid because the first name exceeds 8 characters.