Scriptworks allows for complex flow control structures to be incorporated into tests when required. These fall into two broad categories, Loop structures and Conditional Execution. Both are catered for with pre-defined blocks outlined in the categories below:
Loop structures enable a particular set of test steps to be repeated, either a fixed number of times (For Loops), or while a particular condition is met (While Loops).
A For loop allows for a discrete set of steps to be repeated a number of times. The basic For loop block is shown below:
A numeric value for the number of times the loop is executed can be added manually for a fixed value, or derived from a previously saved value.
Example 1: In this example, we will repeat an account sign up process multiple times, in order to register a number of new users against a SUT:
Note the use of the data generation blocks (from the Test - Data Generation category), to generate random data. Also note the use of the links at the beginning and end of the sequence so that the process returns to a known start and end point, in this case the Home page.
A While Loop allows for a discrete set of steps to be repeated while a condition evaluates to true. The basic While loop block is shown below:
In the example below we will repeat a set of steps whilst a particular Element is displayed:
A break statement enables a loop to be stopped if a particular condition is met.
Let's look at an example of a loop that will execute 10 times unless a message is displayed, in that case it will stop the loop:
Conditional execution structures enable the flow of a script to be altered depending on certain conditions e.g the value of a field obtained during the test or whether a particular element is found or not. There are two basic conditional structure types, If...Then...Else and Switch statements, these are outlined in the sections below:
If.. Then.. Else structures
The simplest If structure is shown in the block below:
In this case the steps contained in the structure will only be executed if the condition specified evaluates as true.
The condition specified can be any block that returns a true or false (boolean) value. This can be a simple string comparison, as shown in the example below, where the Step "Click on ElementB" is executed only if the "Text of ElementA" contains the value "Success":
A comparison could also be with the property of an Element or whether it is present, the example below, shows a comparison with the enabled property of ElementA, "Click on ElementA" is only performed if the Element is Enabled :
Another useful conditional structure is the If...then...else structure. This allows the user to specify an alternate set of steps to execute in the case where the condition being evaluated is false. Note the two sections where steps can be placed. The first section is for steps to be executed should the condition be true, the second if it is not true.
The example below checks if ElementA is enabled and clicks it if this is true, if it is not enabled it will click on ElementB:
Switch structures provide ultimate flexibility for comparing values against multiple options. The basic outline of a switch structure is shown below:
In this case, the value in the switch string can be compared against multiple cases, if a match is found then the steps for that case are executed. If no match is found then the steps in the default section are executed.
In the example below the value of the text in an element is compared:
In this example if the text in ElementA is:
"Click here for more details", then ElementA is clicked on.
"User is not Found", then ElementB is clicked on.
Anything else, then Link1 is clicked.
Conditional Structures and Loops can used in conjunction with Function blocks in order to provide conditional or repeated execution of larger sets of test steps:
Here the RegisterNewUser function block is executed if the text in ElementA contains "Please register to continue".