Skip to content

How do I transfer the execution control from one block of code to other block by a label

This example demonstrates how to skip one block of code using "goto" command and transfer the execution control to other block of code using "label" command.

In the solution shown below, you will see that, the "select" command for selecting an option for "Does Employer offer Health Insurance" dropdown is skipped in HICC based on the environment using "goto" command within "if-endIf" construct and the execution control is transfered to "label" command.

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 construct
If the environment is Production, skip the selection of option in "Does Employer offer Health Insurance" dropdown
1 If "${<Variable Name>}"=="Production"
Transferring the execution control to the label to skip the instruction in between
2 goto Skip_Employer_Offering_Insurance_Selection
End of if block
3 endIf

Select an option from Does Employer offer Health Insurance dropdown
4 select id="dpl_employerInsuranceDropdown" label=Yes
Define Label
5 label Skip_Employer_Offering_Insurance_Selection
Click on Calculate Button
6 click id="btn_calculateControls"

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.
  • You can also have the "goto" and "label" commands in different scripts/scenarios but the script/scenario having "goto" command must be executed before the script/scenario having "label" command.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscore or hyphen.

Feedback and Knowledge Base