Document toolboxDocument toolbox

Header

(8.3.X) Conditional Structure (IF-ELSE)

A test case execution on a run-time can include or skip execution of specific step or tasks as per the specified condition is satisfied.

Key Points

  • You can add If-Else block to a task and test case much like conditional structures used in programming languages, with a limitation that nested IF blocks are not supported.

  • If block has the following structure:

    • IF – ELSE IF –ELSE – ENDIF

    • You can add zero or more occurrences of ELSE-IF and zero or exactly one occurrence of ELSE. Zero or multiple occurrences of IF blocks can be added to a task.

  • It is mandatory to add expression to evaluate for IF and ELSE IF steps. You cannot save these tasks with blank expressions.

  • Expressions are much like the ones used in programming languages.

  • You can form conditions based on the status of previous step, values of environment variables/stored variables and arithmetic, logical and bitwise operators.

  • You can avoid adding a task for adding a single step to test case. A step can be directly added to a test case. It is possible to specify object, action, and parameters to a TC step just like a task step.

Adding Conditional Structures

Inserting Conditional Blocks

Qualitia users can add conditional blocks using the ELSE-IF button.  

Task Level Conditional Blocks

On the task editor screen, click the Add Conditional Block button () to select any of the following conditions:

  • IF

  • Else IF

  • Else

Adding Expression for IF Step

  • Click the Add Conditional Block button, select IF.

  • You can add Else block within an IF block. 

Forming Expression for IF /ELSE IF:

Expressions can be entered for IF and ELSE IF conditional step. User can use stored variables, environment variables as expressions.

  1. Ensure that it is part IF/Else is added after an IF statement.

  2. You can use Numeric, Boolean comparisons, string values, and arithmetic operators.

  3. Environment variables and stored variables should be included in curly braces in expression.

  4. User can save the execution status of last executed step as anyone of the following.

    • Using $$_STATUS directly in expression

    • Saving status of step {$$_STATUS} for use as an expression.
      User can save the execution status of a step in variable. This status can later be used as an expression of IF step.

    • Saving execution status for future reference. You need to use StoreVariable Action and in the second parameter column enter as "{$$_Status}".  For more information about $$_Status and similar variables, refer to Qualitia System Variables

Examples of Expressions:

The following are some examples of valid/invalid expressions, assuming var1 and var2 as stored variables.

Note

  1. The static or dynamic string data used should always be enclosed within double-quotes.

  2. The expression, having string as data, should always be enclosed within double-quotes.

  3. Boolean values are case-sensitive and should be used in lower case.

Data type

Example

Valid/Invalid

Data type

Example

Valid/Invalid

Any

  1. var1=2

  2. var1=var2

  3. var1*=1

  4. var1+=2

  5. var1++

  6. var1=var2+2==10

All are invalid as assignment operator is not allowed in expression

String

  1. ""India"=="India""

  2. ""{var1}"=="{var2}""

  3. India==India

  4. {var1}=={var2}
    (var1 and Var2 are stored variables containing string values)


  1. Valid

  2. Valid

  3. Invalid
    (The string data passed not specified in quotes "" also the whole expression is not inside "")

  4. Invalid
    (Variables containing string data are not specified in quotes "" also the whole expression is not inside "")

Integer

  1. 1==1

  2. {var1}=={var2}

  3. ""1"=="1""

  4. ""{var1}"=="{var2}""
    (var1 and Var2 are stored variables containing integer values or numbers)

  1. Valid

  2. Valid

  3. Valid

  4. Valid

Float

  1. 1.254==1.345

  2. {var1}=={var2}
    (var1 and Var2 are stored variables containing Float values)

  1. Valid

  2. Valid

Boolean

  1. true==true

  2. false==false

  3. TRUE==TRUE

  4. FALSE==FALSE

  5. {var1}=={var2}
    (where var1 and var2 can have value either true or false)

  1. Valid

  2. Valid

  3. Invalid
    (Boolean values are case sensitive. Boolean values should be passed in small case).

  4. Invalid

  5. Valid

Logical operators

(var1=true , var2=false)

  1. {var1}&&{var2}==false

  2. {var1}||{var2==true

  3. !({var1}&&{var2})==true

  1. Valid

  2. Valid

  3. Valid

Arithmetic
Operators

  1. 1+1==2

  2. 1-1==0

  3. 2*2==4

  4. 8/2==4

  5. 9%2==1

  1. Valid

  2. Valid

  3. Valid

  4. Valid

  5. Valid

Relational Operators

  1. 1==1

  2. 1!=2

  3. {Var1}<{var2}

  4. {var1}>{var2}

  5. {Var1}<={var2}

  6. {var1}>={var2}

  1. Valid

  2. Valid

  3. Valid

  4. Valid

  5. Valid

  6. Valid

Bitwise Operators

(var1=60 , var2=13)

  1. ({var1}&{var2})==12

  2. ({var1}|{var2})==61

  3. {var1}&{var2}==12

  4. {var1}|{var2}==61

  5. ({var1}^{var2})==49

  6. {var1}^{var2}==49

  7. ~{var1}==-61

  8. ~~{var1}==-61

  9. ~~({var1})==-61

  10. {var1}<<2==240

  11. {var1}>>2==15

  12. {var1}>>>2==15

  1. Valid

  2. Valid

  3. Invalid
    (Outer () are required,otherwise interpretation goes wrong and it may return false)

  4. Invalid
    (Outer () are required,otherwise interpretation goes wrong and it may return false)

  5. Valid

  6. Valid

  7. Invalid
    (~ itself is a qualitia special character)

  8. Valid
    (escape character ~ is followed by complement operator ~)

  9. Valid

  10. Valid

  11. Valid

  12. Valid

Special Characters

Using Qualitia Special characters:

  1. ""a~xyz"== "a~xyz""

  2. ""a~^xyz"== "a~^xyz""

  3. ""a~{xyz"== "a~{xyz""

  4. ""a~{xyz"== "a~{xyz""

Always use escape character ~ before qualitia special characters ~,^,{,}
For any other character no escape character is required.
e.g ""as#gh%ff"==" as#gh%ff""




All are valid

Adding the Task Step on the TC Screen

You can add the task step using the Add button. After adding the task step, you can add conditional blocks with or without expressions to that step. 

Test Case Level Step (TC step) on the Test Cases Screen

In case you want to avoid adding a task for a single step, you can add TC step. You can then add object, action, and parameters to a TC step just like a task step. 

The TC step can be added at any position, after or before a task or even as a first step of test case.

To add TC step:

  • Focus on task and click the TC Step button. You can then use Up and Down buttons to move the step up or down. 

Adding A TC Step and Task Step

  • To add an independent TC step, click  the Test Case Step button (

    ).

  • To add a step into a task, click the Task Step button (

    ).

Storing Execution Status of TC Step

The execution status of TC step can be stored the same as the task step.

ELSE IF Blocks on the Test Cases Screen

On the Test Cases screen you can add conditional blocks to task and Test Case. The Test Case level ELSE-IF blocks can contain tasks and the contained tasks in turn can have task level ELSE-IF blocks.

Adding the ELSE-IF Blocks to Test Case

You can add the TC or Task condition using the ELSE-IF button from the Test cases screen.

To add TC or Task Condition:

  1. Select TC Step/Task after which you wish to add TC level conditional block.

  2. Click Add Conditional Block >TC Condition > IF.

  3. .Select IF step of block, click the TC Step button to add TC step.

  4. Select recently added TC Step:

    1. Click Add Condition Block >TC Condition >ELSE IF to add TC level ELSE IF block.

    2. Click Add Condition Block >TC Condition > ELSE to add ELSE block.
      Note: If you want to add an Else-If or Else condition, it must be added after the If condition. 

Adding Tasks in Test Case Level ELSE-IF Blocks

You can add new tasks or import tasks from the existing library of tasks inside the conditional blocks. 

To add tasks in TC level ELSE-IF blocks:

  1. Select TC Step/Task after which you want to add TC level conditional block.

  2. Click Condition >TC Condition > IF.

  3. Select IF step of block and then click New to add new task or Import to add the existing task to the conditional block.

  4. To add Tasks to ELSE-IF or ELSE blocks, select the ELSE-IF or ELSE step of the conditional block.

  5. Do one of the following to include  a task:

    • To add a new task, click the New Task button (

      ). 

    • To add an existing task, click the Import Task button (

      ).

      Note: If you want to add an Else-If or Else condition, it must be added after If condition. 

Adding ELSE-IF Blocks to Task in TC

You can add the conditional blocks particularly for task. 

Note: If you want to add an Else-If or Else condition, it must be added after If condition. 

To add conditional blocks to a task from the Test case:

  1. Create a new test case and add required tasks to it. 

  2. Select the step after which the conditional block needs to be added, or the task row to which the block needs to be added.

  3. Click the Add Conditional Block button > Task Condition > IF.

  4. Once If block is added to task, ELSE IF or ELSE blocks can be added by selecting proper task step and using the ELSE-IF button. 

  5. For adding expression, double-click IF or ELSE IF.

  6. Use the syntax of expression is as described earlier.

Execution flow of conditional (ELSE-IF) blocks will be as follows:

  1. Qualitia validates expression entered by the user and checks if the expression is empty or contains assignment (for example, if user entered a=b which is invalid). Expressions should not have assignment, users should use "==" operator instead. Hence {a}={b} is invalid expression.

  2. Rest of the syntax and semantics is checked during the actual execution of test case.

  3. You must enclose stored variables, environment variables in curly braces (for eg: {a}=={b}, or ($$_Status}==0.

  4. Consider the following test case level conditional block:

    1. OpenUrl

    2. IF {$$_Status}==0
      Task1
      Task2

    3. ELSE IF {$$_Status}==1
      Task3

    4. ELSE
      Task4

    5. END IF

If during execution, the step OpenUrl is successful, then Task1, Task2 is executed.

If the step OpenUrl fails, then Task3 is executed.

If the OpenUrl has execution status other than 0 or 1, Qualitia executes Task 4.

Qualitia's Behavior in case of Invalid Expression:

  • If the expression is invalid, for example, expression has stored variables referred but not declared, or the syntax of expression is invalid then the test case is considered to have an error and Qualitia will stop execution of test case.

  • When execution is triggered using the Dry Run button from the Develop tab and if the expression is invalid, Qualitia stops execution of test case.

  • When execution is triggered using the Run Now button from the Execute tab and if the expression is invalid, Qualitia executes next test case. If there is only one test case, execution will be stoppped. 

In all such cases, Error log in reports will explain the reason of execution failure so that users can take corrective actions.

Test Case Iteration Report for Conditional Structure

The test case iteration report that contains the IF_Else conditional statements displays associated results in a hierarchy. The condition "IF" is the parent node for Else If, Else, and End If statements. No status is shown for the conditional statements (IF-ELSE IF –ELSE and END IF) as they are constructs and not actions.

The steps in conditional block are mentioned in the report only if expression evaluates to "true". Steps of blocks whose expression evaluates to "false" are omitted from report as these steps are not executed.

Handling Special Characters In Conditional Expression

In Qualitia Automation Studio, while adding data for validating conditional expression, you can add the string values. Sometimes, these string values can contain JavaScript special characters, such as double quotes, single quotes, and backslash (",',\).

When adding string with such characters as data into Conditional Expression, you must use an escape character. As the name suggests, this escape character allows you to get the desired output without treating these characters as special. You can use backslash (\) as a JavaScript escape character in case you have characters like double quotes, single quotes, and backslash (",',\) in the conditional expression data.

As shown in the screenshot below, if you are using values like single quotes, double quotes or backslash in conditional expression, you need to use escape character (/).

Important Note

In case you have any special characters into the variable value, Qualitia automatically handles them while using it as a conditional expression data.

For example, if you are using StoreVariable action to store some value and that value contains JavaScript special characters. Later, if you use that variable in the conditional expression, you no need to handle special characters from the value. Qualitia automatically handles them while using it as conditional expression data.

Limitations

  • Nested IF blocks are not allowed

  • Task level IF, ELSE IF or ELSE blocks can be moved up or down within the task whereas test case level IF, ELSE IF or ELSE blocks cannot be moved up or down.

  • $$_Status can be used only for step's execution status. There is no provision to store or refer Task's execution status.

  • A test case level step cannot be moved to task, or multiple test case level steps cannot be moved to new or existing tasks.

Frequently Asked Questions for Conditional Steps

  1. Select IF.

  2. Click on remove step.

  3. User is provided with the following three options:

    1. RemoveBlock: On selecting this option, all steps (including intermediate ELSE IF / ELSE) will be removed from Task.

    2. RemoveCondition: On selecting this option, only conditional structure of block is removed, all steps are retained.

    3. Cancel: Exits the popup or return.



  1. Select ELSE IF or ELSE.

  2. Click on remove step.

  3. User has the following three options:

    1. RemoveBlock: On selecting this option, all steps under ELSE IF / ELSE including the selected ELSE IF or ELSE will be removed from Task.

    2. RemoveCondtion: On selecting this option, only selected ELSE IF or ELSE is removed. Steps are retained and they will execute as a part of upper IF or ELSE IF, whichever is present.

    3. Cancel: Exits the popup or return.



  1. Select the condition you want to remove (IF/ELSE IF/ELSE).

  2. Select option “RemoveCondition”.



  1. Select the TC step you want to move.

  2. Click on Move Down.

If the TC step you want to move follows a task, TC step will be moved after a task. If the TC step you want to move follows a TC step, the step will be moved after that TC step.



  1. Select IF.

  2. Click on remove step.

  3. User has the following three options:

    1. RemoveBlock: On selecting this option, all steps (including intermediate ELSE IF / ELSE) will be removed from Task.

    2. RemoveCondition: On selecting this option, only conditional structure of block is removed, all steps are retained.

    3. Cancel: Exits the popup or return.













Footer