How to use if else in Tosca

If else in Tosca is used to control the flow of the script using a defined condition.

In the below example, we are trying to log in to the Demo webshop, and below is the if condition structure

If (Error Condition == “”)
Then (Verify user logged in successfully)
Else (Verify error message for invalid user)

Tosca Test Case Structure

How to create if else in Tosca

Right-click on the folder and in Ribbon click if the condition icon

How to create if condition in Tosca

In the Condition block, Add the TBox evaluation tool and give the required condition in it, and in the block mention what set of validations needs to be done if the condition gets passed

Evaluation Tool

Right-click on the if condition and select the else block from the Ribbon menu

Else Block Selection

In this example, We passed an invalid username and password. Based on the above condition we provided, we expect the condition to fail and the script should proceed with else block

If else in tosca

I hope the article was useful. Kindly reach out to us if you have any issues with Tosca

Best Practice :- In Tosca, if condition should be used only if you don’t have any alternative options like TestCaseDesign conditions

Leave a comment