Conditional Checks such as If, Else, Else-If highly increases the control over the Execution Flow of Test Cases. A conditional check can be included in the Test Steps quite easily using Testsigma. Let us demonstrate the steps with an example below:


Pre-requisites

You need to be familiar with basics of Test Case creation and Execution. Also, Familiarity with Test Step creation is expected. Check the following resources if you are new to Testsigma.

How to add/edit/delete an automated Test Case?

How to add Test Steps for Web Application Automation Testing?


Also, basic knowledge about conditional statements such as If, Else-If, Else and their usage for the conditional flow of a program in beneficiary.


Example

Let us consider the following scenario:


Creating Conditional Test Steps


We can create a new Test Case or continue adding Test Steps to an existing Test Case. Let us quickly create a Test Case named 'Sample Conditional Check Test Case'.

1. After creating a Test Case, click on Create Test Step button to add the first Step.


2. Create a Test Step to navigate to the Test Page using the template go to test data and replace test data with 'https://en.wikipedia.org/wiki/Test_automation' as shown below:



3. We can now check for the presence of a Link with link text 'Software Development' using the template The element ui identifier should display text test data. Replace ui identifier with UI Identifier for the link and test data with the String 'Software Development'(without quotes).



4. After entering the template and replacing the required data, click on the Add Conditional If checkbox above the Action Textbox to convert the Test Step to a Conditional Check Test Step.



5. Select the expected outcome after the execution of Test Step from the drop-down menu(Passed, Failed, Aborted, Not Executed, Prerequisite Failed, Queued, Stopped) and click on Create.

In this case, we have selected Passed since we want to make sure the condition passes if 'Software Development' link is present.


6. Hover over the right end of the most recently created Test Step to reveal new options Else, Else-If along with the Add before and Add after buttons as shown below:



We have a number of options at this point:

  • Click on the Add After to add a nested Test Step that executes if the above condition is satisfied i.e 'Software Development' link is present.
  • Click on Add Before to add a normal Test Step before the conditional If Test Step.
  • Click on Else If to add an Else-If condition that is to be checked if the previous If condition fails i.e 'Software Development' link is not present.
  • Click on Else to add an Else condition that readily executes when the above given If and If-Else conditions fail.

You need to note that there can be multiple Else-If Test Step groups but there can only be one Else group. Also, every If condition usually has an Else group but not necessarily.


7. Now, since we need to perform a few steps if the link with text 'Software Development' for the Element with UI Identifier 'softdevlink' is present, we will be adding those steps using the Add After button. These step will only execute if the above condition is satisfied.


8. Click on Add After button and add the Test Step to click on the Software Development link as shown below:



9. Click on Create and Continue and then add the Test Step to verify the page URL as shown below:


10. Create the next step to go back to the previous page:


11. Now, we need to add the Else group of Test Steps that execute when the If condition fails i.e. Software Development link was not present in the Test Page. Go back to the Test Step #2 and click on Else button by hovering at the right edge.


12. Click on the Add After button on the Else Test Step to add a Test Step to Else group of Test Steps.


13. Create the Step to verify the page URL is indeed "https://en.wikipedia.org/wiki/Test_automation".



Here's the final list Test Steps in the complete Test Case:



Conditional Steps in Test Results


The total number of Test Steps in the Test Results Page will be equal to the number of non-conditional steps i.e excluding the Steps starting with If, If-Else or Else.

The reason for this approach is that Conditional Test Steps are not considered as actual Test Steps. They are just checking for conditions on the basis of which the Actual Test Step should be executed or skipped.

You can always check the total number of Test Steps in the Test Case details page.


Also, The failed Conditional Steps will be shown as failed in Test Results and the nested Test Steps below a failed Conditional Step will be skipped and wouldn't be shown in Test Results.



That's all we need to get started with Conditional Test Step Execution using Testsigma.


Happy Automation Testing!