How do I use the Switch/Case Action in ScenarioBuilder?

This article provides an overview of how to use the Switch/Case control actions. It also presents scenario examples for its use in a script.

ScenarioBuilder scripts are meant to mimic human behavior. When working with an application, humans make decisions. ScenarioBuilder provides options for emulating the decision-making process in a script. This article focuses on using the Switch/Case control action.

The Switch/Case action is appropriate when your condition is always “equal to” and you have multiple values possible in the variable. If you need to handle other operators like “greater then”, “less than”, etc., then you will need to use the If action.

Basic Steps to Add Switch/Case Action

To start your Switch/Case action, drag Switch from Control Actions. It places a Switch step, along with Case and Default child steps.

  1. To start your Switch/Case action, drag Switch from Control Actions. It places a Switch step, along with Case and Default child steps.
  2. Select the Switch step and enter your variable in the Variable Name property. It must be enclosed in % (i.e. %variablename%).
  3. Click the Case step and enter the first variable value in the Variable Value property.
  4. Add the steps that should be executed when the variable is equal to the value entered. Remember to make them child steps under the Case step.
  5. To add another Case step, drag Case from Control Actions and place it between the existing Case and Default steps.
  6. Enter the variable value in the Variable Value property.
  7. Add the steps that should be executed when the variable is equal to the value entered. Remember to make them child steps under the Case step.
  8. Repeat steps 5-7 until all needed Case statements and steps have been added.
  9. Under the Default step, add what steps should be taken when the variable value doesn’t match any of the Case values.

Scenario 1 - Numerous Checkboxes on a Form

I am automating filling out a form and it has a question about reason for visit with 5 checkbox options. The CSV file has a variable for visit reason. My logic looks like this:

If reason for visit is equal to value, select the corresponding checkbox.

My switch/case would look like this:

Switch case actions-1

I didn’t add any steps for Default since I don’t want it to do anything if there is a value in the visit reason variable that doesn’t match any of the Cases.

Scenario 2 - Randomizing options

Let’s use the same scenario, but this time we don’t care what checkbox is selected. So instead of the value for visit reason coming from the CSV file we want the script to randomly select a checkbox.

First, add a Set Number Variable action to your script and set it to randomly generate a value between 1 and 5 which represents one of 5 options and give it a variable name.

Next add the same Switch/Case statement but change the Case values.

Switch case actions-1