Using Conditional Statements in QTP
Posted on March 02nd, 2009 in QTP Lessons
Conditional statements enable you to control the flow of your Test or component. You use the IF … THEN and ELSE statement to incorporate decision-making in your tests. The IF … THEN statement evaluates whether a condition is true. If the condition is true, the statements following IF … THEN are executed. If condition is not true, the statements
following the ELSE are executed.

The syntax to add an IF … THEN and ELSE statement to your test is:
If [condition] Then
[statement]
Else
[else statement]
End If
Adding a CONDITIONAL STATEMENT: To add an IF … THEN step in KEYWORD VIEW:

- In KEYWORD VIEW, select the step where you want to add the conditional statement.
- From the QuickTest Professional menu bar, select INSERT ? CONDITIONAL STATEMENT ? IF … THEN. The STATEMENT step is added in KEYWORD VIEW.
- Click the STATEMENT step. The step changes to a list.
- From the STATEMENT list, select the type of step that you want to add.
- Select an object from Object Repository and ensure that the operation is correct.
(For example, EXIST, ACTIVATE, or CLICK). - In the VALUE column, type a value that you want to set for the IF statement.
Selecting Statement Type: To add a conditional step to a test in KEYWORD VIEW:

- From the QuickTest Professional menu bar, select INSERT ? CONDITIONAL STATEMENT ? IF … THEN. The STATEMENT step is added to KEYWORD VIEW.
- Click the STATEMENT in the IF step. The step changes to a list.
- Select one of the following statement types from the list:
– OBJECT FROM REPOSITORY
– Step Generator
Related posts:
Tags: QTP Lessons