If you are a programmer or if you know the basics, you might already be familiar with Conditional ‘If’, ‘Else’ and ‘Else–if’ statements. Even If you haven’t heard about these yet, this article would be helpful.
The conditional statements in general, help take actions depending on whether a programmer-specified condition or criteria evaluates to true or false.
In Testing context, these Conditional statements provide control over Test execution, i.e the flow of test execution depending upon the conditional steps. To understand this, let’s write a sample test case.
Example 1: If and Else
Step 1 : We start with a simple Go to step.
Step 2 : Click on Add Next Step. When the new Test Step box appears, tick the checkbox “Add Conditional If”.
Now, select the expected outcome after the execution of Test Step from the drop-down menu(Passed, Failed, Aborted, Not Executed, Prerequisite Failed, Queued or Stopped).
Here we select “Passed”. Let’s move on to add a Test Step. I’m using the grammar, “Verify that the element swdLink displays text Software development“. Now click Create.
Here, “swdLink” indicates the ui identifier.
“Software development” is the test data(are input values that we give; say, in an input form like date, name like john, etc).
Step 3 : Hover over the right end of the If Test Step to reveal new options:
Else, Else-If along with the Add before and Add after buttons.
Click on the Add After icon.
Let us add another Test Step, “Click on the link with text Software development” and click on Create.
As you might have already understood, Software development here is nothing but test data.
Step 4 : Again hover over the If step and click on the Else option.
Now click on the Add After button to add another Test Step to the Else condition.
Step 5 : Hover over the Else step and Click on the Add After button to add the test step.
Add the step “ Click on the Refresh button in the browser”.
Now run this test case.(You may refer Dry Run if you are not already familiar how.)
The If step group will be executed as the condition is satisfied. But, the Else group steps won’t be executed and will be shown as Failed in the result.
Example 2: If, Else-If, and Else
To do this, we will use the previous example with some modifications. Change the test data from Software development to Hardware development in the If group so that the If condition fails.
Hover over If step and click on Else-If and add the step “Verify that the element software development link displays text hardware development”.
Add the step “Click on the link with text Software development” inside the else-if group.
Run results of this case will show that the Else-If group passed.
Both If and Else group conditions fail and the test steps inside these will not be executed.
That is how we can use If, Else-If and Else in Testsigma. Hope you got an idea of how it works.
Feel free to reach us at firstname.lastname@example.org or leave your message in the chat section and, we’ll be with you!