There are a number of tools within TestStand that allow you to programmatically control the flow of steps depending on results, variable values or other conditions. Below are listed the fundamental tools used to control the flow:
Post-ActionsYou can use the
Post Actions of any step and / or a
Goto step type allow to jump to another step in a sequence.
- Select a step and navigate to Step Settings and select Post Actions
- In a Goto step, simply choose the desired step from the drop-down labeled Destination Step.
- In the Post Actions of a normal step you can check the Use Custom Condition box and then choose Goto Step from the drop down under the On Condition True or On Condition False section, you may choose different steps depending on the step result (the default condition is pass or fail). Then, you can choose your destination step from the second drop-down in the section you chose.
For example, you can check the value of the Step.Result.Error.Code property of any step and jump to a specific step if a specific run-time error occurs, or the Step.Result.Error.Occurred property instead for any run-time error.
Normally this process allows you to only go to any step in the current, or next step group, but not to a previous step group. However you can use the RunState.NextStepIndex and RunState.StepGroup properties to jump to a previous step group. RunState.NextStepIndex contains the zero-based index of the desired step that follows the currently executing step in the step group indicated by
RunState.StepGroup. By modifying the value of these properties, you can specify the step that TestStand executes next. For example, if you are in the Main step group and you want to make TestStand jump to the first step in the Cleanup sequence, you can have the following expression in a Statement step:
RunState.NextStepIndex = 0, RunState.StepGroup = "Setup"
The valid values for the RunState.StepGroup property are: Setup, Main and Cleanup.
Preconditions
You can use Precondition to only allow a step to run if a certain condition has been met, for example, a test must have passed, or failed or executed to run.
- Select a step and navigate to Step Settings and select Post Actions
- Here you could choose to only run if a known variable was equal to a specified value.
- Alternatively you can use the Precondition Builder. (shown in image below)
- This allows you to more easily define your condition and insert new expressions dependant on the result/state of specified steps.
Flow Control StepsThese steps are available from the
Flow Control folder of the
Step Types in the Insertion Palette (Shown in Image below).
The steps enable users to add conditions the program and enable coding functions such as
If, Else, Else If, While and For.Similar to the
Preconditions, the condition builder is available to assist in the building of the expression that will be used to control the flow.
Additional Information
The
Post Action method can be combined with the SequenceFilePostStepRuntimeError Engine Callback for more flexible approaches. Refer to
Handling TestStand Runtime Errors and the
Overriding SequenceFilePostStepRuntimeError Callback TestStand shipping example for more information about the SequenceFilePostStepRuntimeError Engine Callback.
This solution doesn't work for versions prior to TestStand 2.0.