Skip to content

How to script conditions using if-else-endIf construct

This example demonstrates how to script conditions within a test script using Conditional Flow Control commands.

In the solution shown below, you will see that the web site title of the Production environment of HICC launched is being validated. You can use the "if-else-endIf" construct to achieve the same.

Note: You can use store or storeXXX command to define the value (string or boolean) of the variable. The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.

Solution:
# Command Target Value
Start the If contruct
If the environment is Production, then the Production environment title is verified  
1 if "${<Variable Name>}"=="Production"
 
Verify the Title for Production environment
2 verifyTitle Health Insurance Cost Calculator - Production  
Else the environment is not Production, then the instructions in "else" block would be executed which is to print an error message using "echo" command
3 else    
4 echo Production environment title verification failed       
End the If construct
5 endIf    

Tips, Tricks, Gotchas & Best Practices:  

  • To know more about how to initialize a variable, click here.
  • The value for the variables can also be driven from a Data-fileSystem Defined Variable or User Defined Variable. To know more about the best practices of driving data into the tests, click here. 
  • In conditions, while comparing numeric values, do not use double quotes("), as it would consider the value as a string.
  • As a best practice, you are encouraged to use an "elseIf" condition avoiding the usage of multiple "if-else-endIf" constructs.


Feedback and Knowledge Base