Adding Conditions to Test Cases

Adding conditions to Test Case allows you to perform different actions while executing your test. Conditions in Sofy follow the If and Else statement workflow that can be defined as executing a certain step or skipping it to move onto the next step.

For example:

Depending on the OS version, your App surfaces a permissions dialog box, asking the user to select "Allow" or "Don't Allow" as an option before moving to the next step. With the Conditions feature enabled, you can either let the test case continue if the dialog box appears or move on to the next step if the dialog box doesn't appear. With this feature you can now take into account the App behavior depending on the OS version and ensure that the test case is executed as intended.

How to use Conditionals?

  1. Click on the Automation tab from the left panel on your Home Screen

  1. Click on the Edit icon (pen) next to the test case inside which you wish to insert a Conditional. For example, let us insert a Conditional inside “test3” here.

  1. Inside the Edit Test section, select the step over which you wish to insert a conditional. As an example, let us select Step 2.

  1. In the action bar of the step which pops up, select the icon with the curly braces which denotes Conditionals.

  1. In the Add Condition dialog box, select the element over which you wish to insert a conditional. In our case, let us select the element “Allow”.

  1. After making the selection, choose your desired option from the “Verify That” dropdown and after that, choose if you wish to skip this step or if you wish to execute this step in the same fashion as you recorded originally.

  1. After finishing up, simply click on the “Add Conditional” button inside this dialog box and voila! At time of execution, if there is no dialog box surfaced, Sofy will skip this step and move onto the next step to complete the test execution. And if the dialog box does appear, it will execute as was in the original recording.
  2. A yellow curly braces icon signifies that a conditional has been added to that step.

  1. When executing a test with conditionals, a yellow curly braces icon denotes that a conditional was applied to that step. For example, on step 2, there was a conditional applied where the original action was a click.
  2. Additionally, when you check Test Results located in the Runs & Report section, you will see the conditional step marked with a yellow tag. Moreover, in the details section of that step, you will find the conditions applied.

  1. If you skip a certain step, it will appear with the label "Step(s) Skipped". To view the step skipped, you can click on Show Me:

Common Scenarios with Conditionals:

In this scenario, we would like to execute a particular step on the basis of a non-textual component not being visible on the screen and the component in question does not share class or resource ID values with other visible elements. 

In this scenario, the element in question is either: 

  • Truly absent from the screen. 
  • Not rendered at all in the current view. 

The most reliable assertion in this case is to verify that the component does not exist in the current UI tree. This ensures we are not detecting any off-screen or hidden variations of the element. 

By asserting "Component Not Present", we confirm: 

  • The UI is in the correct state. 
  • There are no premature or unexpected component renderings. 

Let's see how it works!

  1. Select the Assert Type 
    1. From the dropdown menu under Verify That, select Test component is not present. 
    2. This ensures the condition checks if the test component is not present on the screen. 

 

 

  1. Choose the Action for the Condition 
    1. For the action,Then, click the dropdown and select Execute Step as Recorded. 
    2. This means if the test component is not present, the recorded step will be executed automatically. 

 

 

  1. Finalize Adding the Conditional 
    1. After selecting the condition and action, click the Add Conditional button to save this condition. 
    2. You also have the option to Skip This Step under the Else scenario if the condition is not met. 

                    

 

 


How did we do?