How to script multiple conditions using if-elseIf-else-endIf construct
In the solution shown below, you will see that the web site titles are being validated based on environment of HICC launched. You can use the "if-elseIf-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 If the environment is QA, then the QA environment title is verified | |||
| 3 | elseIf | "${<Variable Name>}"=="QA" |
|
| 4 | verifyTitle | Health Insurance Cost Calculator - QA | |
| Else the environment is neither Production nor QA, then the instructions in "else" block would be executed which is to verify the title of Integration environment | |||
| 5 | else | ||
| 6 | verifyTitle | Health Insurance Cost Calculator - Integration | |
| End the If construct | |||
| 7 | 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-file, System 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.
|
|
|



