Control Statements
Control Statements
(New)
We want to make your University of Provar experience as accessible as possible. Please note
that you can navigate directly to lesson content and skip sidebar navigation if you are tabbing
through our course with a screen reader. You can also use these keyboard shortcuts for
alternative navigation.
NOTE: Provar Automation Advanced courses are best completed in conjunction with the use
of our Automation product. Please contact [email protected] to learn more about
becoming a customer.
Getting Started
Control Statements
Switch
LOOPING
Introduction to Looping
Wait For
While
For Each
FINALLY
Finally
WR AP UP
Quiz
Course Transcript
Getting Started
This course should take about 60 minutes, and you will earn an Advanced Control Statements
badge upon completion.
Lesson 2 of 14
Control Statements
Provar Studio
When you are working in Provar Studio, you can access control statements in the Test Palette, which is the
As you are building your tests, you can also access the Test Palette and its control statements in Test
Builder.
Lesson 3 of 14
path the test takes will change depending on the information received. In other words, a conditional
statement checks if certain conditions are met to determine which actions to execute next. We'll cover two
control statements that use conditional logic in this section:
If statements
Switch statements
Source
Lesson 4 of 14
If Statement
What is an If statement?
An If statement evaluates a condition to determine which sub-steps will be executed if the
boolean condition returns as true. It is usually coupled with an Else statement, which contains the
different set of steps to execute if the boolean condition is false. Simply put, you can define
different sets of steps for each Boolean result of the statement. You might think of it like a flow
chart written into your test case.
Now let's think about it in a test case. In this scenario, we will evaluate if the test step returns the
text This is a test when executed. If the text is present, then the condition will return as TRUE. This
means that the next step will execute Then to assert the values under that test step.
If the text is not present, then the condition will return as FALSE. This means that the the next step
will not execute Then. Instead, it will execute Else, which will assert the values for that test step.
Click through the numbers below to see how this would look in flow chart form.
If Statement
True
Execute If step
Because the condition is true, the If step will execute Then to assert the values under that step.
False
Because the condition is false, the test will execute the Else step to assert the values under that test step.
Now let's replace those flow charts with an actual test case using the same scenario described
above.
If Statement
Evaluate if the test step returns the text flag when executed
True
Execute If step
Because the condition is true, the If step will execute Then to assert the values under that step.
False
Because the condition is false, the test will execute the Else step to assert the values under that test step.
Drag the If test step from the Test Palette into your test case.
Condition: Provide the condition in the If statement. Based on that, you will get the Boolean
result.
Then: This is a grouping of sub-steps which should be executed only when the If condition
evaluates to TRUE. This grouping is required and is added automatically under the If step.
Else: This is an optional grouping of sub-steps which should be executed only when the If
condition evaluates to FALSE. To add an Else clause to the If statement, right-click on the If test
step and select the Add an Else Clause option
Step 3
If you want to use Contains as a logic in the If statement, you can use the ~ operator. Note that
the Containing string needs be written between .* and .* as shown in the image above.
Lesson 5 of 14
Switch
Let's consider an example with sports, specifically football and cricket. Similar to the different
rules and equipment we have for each sport, we'll also have different steps we want to execute
for each sport in our test case. If Football is returned, then we want only the values for Football to
be asserted. If Cricket is returned, then we only want the values for Cricket to be asserted. These
Another option you have in Automation is to include a Default case. This serves as a catch-all
group step that will run if none of your expected conditions are met. For example, if Soccer or
Basketball are unexpectedly returned, then the Default clause would execute those edge cases.
It's a recommended practice to put Default clauses at the end of the Switch block.
Take a look at this in a flow chart. You'll see that even though we've outlined two sports, there are
three options depending on the value returned because we also added the Default clause.
Now let's look at that same scenario written into a test case. Notice the Break statements after
each Case statement. Without them, all Case and Default clauses would execute every time,
defeating the purpose of the Switch statement. To add the Break statement to your test case,
simply drag it from the Test Palette.
A Switch statement is a way to streamline a series of If-Else
statements and create more complex logic without nested
statements.
Drag Switch from the Test Palette into your test case. Then, provide the value in the
Value parameter.
Switch statements come with one case by default. To add a case or default a case, right-click on
the Switch test step and select the option to Add a Case/Default Clause.
Note that you can add multiple case clauses in the test case based on your requirements.
Summary
That's it! Once you save the test case, your Switch step will be ready to go.
Automation will automatically add one Case clause with the Switch step. You can add another Case clause
or a Default clause by right-clicking on the Switch statement and selecting Add a Case Clause or Add a
Default Clause. You can have as many Case clauses as you want in your test case, but you can only have
one Default clause.
Lesson 6 of 14
Introduction to Looping
What is looping?
Looping repeats actions based on conditions that are set. It creates an iterative process in your testing, so
you can think of it as creating loops that run through and repeat a set of actions. Looping helps testing
because it saves time and reduces errors. We'll cover three statements that use looping:
While statement
Wait For
Let's dig into an example. Assume we have a dynamic element on the page, but the time that it
takes to show up on the page is inconsistent. We can use a Wait For step to help us here.
Wait for a Dynamic Element to Appear
Step 1
This will update the status of the visibility. The variable name will be the same as the first reading
of the element visibility.
Condition
This is the condition that needs to be reached for the test to continue. You can define it using the build-in editors.
Test First
Max Attempts
Sleep For
The time in seconds that the sleep time should last. Note that this can exceed 60 seconds.
Continue On Failure
Check this box if the wait-for time should continue after failure
3 One of the iterations encounters an error, and the Continue on Failure box
is unchecked.
Lesson 8 of 14
While
You are iterating through a list and you want to specify an end value as a
conditional exit for the loop.
You have some more advanced logic and want to update the condition
inside the loop by using the counter as an indexer for a list, etc.
You want to loop indefinitely and perform some group of actions that are
not conditionally based.
Let's look at a While loop in a test case. In this scenario, we want to create five account records,
so we used a While loop will run up to five times depending on if or when the condition is met.
Click to enlarge the image.
Condition
This is the condition to be reached for the test to continue. You can define this using the inbuilt editors also.
Counter Name
Start Value
End Value
This is the end value of the counter. Looping will automatically end when the loop reaches this value. If the value is
less than the Start Value, then the counter will decrease with each execution instead of increasing.
Continue on Failure
For Each
A For Each loop allows you to iterate over elements of a collection, such as an array, list, or any
other iterable data structure. For example, in the spreadsheet below it would iterate through the
data on rows 2 through 11.
The benefit of a For Each loop is that you do not have to specify the loop's initialization, condition,
and increment explicitly. Instead, you provide a way to access each element of the collection, and
the loop automatically iterates through all the elements.
With the For Each loop, you can easily iterate over a list by
performing a repeatable action using the data in each row
or index of the loop.
Let's consider an example in a test case. In this scenario, we want to create multiple opportunity
records using the data provided in an Excel sheet. We can accomplish this in two simple steps.
Read the Excel sheet data
Read the data into your test case by adding a new parameter value source (covered in Provar Automation
With the data read into the test case, the For Each loop will iterate through the data to repeat the steps to
List
From Item
A particular value from the collection (e.g., 1) that indicates where to begin the first iteration of the loop
Value Name
Continue on Failure
If the For Each loop should continue after failure of any iteration within the loop, check this box.
The For Each loop will exit in two conditions. The first is when the index of the list/array set in the
List parameter has reached the end of its values. The second is when one of the iterations
encounters an error (failed test step or execution), and the Continue on Failure box is not
checked.
Lesson 10 of 14
Finally
to the next scenario for batch execution or terminated for single scenario. In some instances, though, you
may want to execute some steps at the end of the scenario before the control shifts to the next one or
The Finally statement creates a grouping of test steps that are always executed even if prior test steps have
Include a Finally step to run reporting steps, such as updating the test
result into a spreadsheet.
If you want to clean up the data created during your test execution, you
can include those clean-up steps inside the Finally statement.
Use a Finally step to update the test case outcome in apps such as Test
Rail or JIRA regardless.
Let's look more closely at that last example. On a successful execution, Pass should be updated,
and on a failure Failed status should also be updated. We can use a Finally statement to update
that status after the run, but we also need two different sets of steps depending on the test
passing or failing. Sound familiar? We'll need to use an If Else statement to branch within the
Finally step. Check it out below.
Quiz
Question
01/05
~
Question
02/05
Automation will automatically add the number of Case clauses you need
03/05
True or False: The steps under a Finally statement will be executed even if there is a prior
failure.
True
False
Question
04/05
True or False: You can set a sleep time for more than 60 seconds with a Wait For loop.
True
False
Question
05/05
You've also earned a Advanced Control Statements badge. You can view your badge under “My
Badges” on UP.
Lesson 13 of 14
Course Transcript
(https://provar.com/release-note/spring-24-release-1/)
(https://provar.com)