Pursuing our QTP training series with Tutorial #4 on implementing Conditional and Loop Statements in Keyword View.
Comprehending the functionalities of QTP’s keyword and expert view is vital for grasping QTP. This KeyWord View tutorial is presented in four parts, and we are presenting the third part in this sequence.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
=> Click Here For The QTP Instructional Tutorial Series
What You Will Learn:
Incorporating Conditional and Loop Statements in Keyword View
A synopsis of what we have discussed until now- –
We’ve acquainted ourselves with QTP’s Keyword View and are investigating the various attributes it provides. We are utilizing a fundamental instance of recording basic operations on the Sample Flight Application in order to understand how QTP converts these steps into a table in the Keyword View. QTP not only exhibits the procedures as a table, but also facilitates users to tweak the steps straightaway in the view.
We have already gained knowledge on how to incorporate standard steps in Keyword View. Apart from standard steps, this view also showcases conditional and loop statements in a test.
This article will delve into how Keyword View of QTP manages these statements.
Initially, what are the roles of Loop and If statements?
Loop Statement: This statement is employed in programming logic when a set of statements needs to be performed repeatedly for a certain number of iterations. Another variant of this statement is to reiterate execution for a chunk of code until a specific condition is satisfied or as long as the condition holds true.
If statement: The ‘if’ statement is utilized in a program to verify if a given condition is met. When it is, a specific chunk of code will be executed. ‘if…else’ and ‘if…else if…’ are variations of the ‘if’ statement.
Each of these statements is represented by distinct icons in Keyword View. Let’s incorporate some dummy steps in our program and scrutinize how these statements feature in the Keyword View. As these steps we intend to incorporate are dummy steps, I will straightforwardly insert the code into the Expert View and examine it in the Keyword View.
#1) Conditional Statements
Detailed above are the various variants of the ‘if’ statement that I inputted into Expert View. Note that this code doesn’t serve any real purpose and is considered for illustrative purposes only. Now, let’s consider how these statements are depicted in the Keyword View.
As can be observed, each statement is assigned a unique icon for distinct identification.
#2) Loop Statements
We will now examine the representation of loop statements. The same procedure will be followed as for the conditional statements.
Incorporating Conditional Statements into the Keyword View
In the examples above, I introduced conditional statements from Expert View and we merely glimpsed at their representations in Keyword View. Now, let’s inspect how to incorporate them directly from Keyword View. Here’s the procedure:
Click any location in the Keyword View, in a similar way you would to append a standard step. Right-click and choose “Insert->Step,” followed by “Conditional Statement,” and select the appropriate statement.
This is how it appears:
As shown above, based on your requirements, you can opt for “If…Then,” “Elseif…Then,” or “Else” statements.
Let’s select an ‘if…then’ statement and observe what transpires.
This is what gets included. To explain the ‘Then’ part of our ‘if’ statement, we need to introduce a conditional statement. Comparable to adding a standard step, we need to define the following columns:
Item: Click on the ‘item’ column equivalent to the ‘if’ statement to view available objects. Choose the object you wish to act upon. For instance, if we desire to verify if the ‘Password’ field exists, we select “Password” from the list.
Operation: Clicking on this column exhibits a list of available functions. As we are validating if the password field exists, we choose ‘Exist’.
Value: This field is for the argument(s) of the function. For the ‘Exist’ function, no argument is necessary, so we leave it vacant.
Now let’s scrutinize how this new statement appears in both the keyword view and expert view.
Keyword View:
Expert View:
As you can observe, the ‘if’ statement is explained.
Now we should add code or statements to define what needs to be executed if the condition is found to be true. For instance, if the password box exists, we will feed a value in the field. Any steps recorded or added after adding a conditional or loop statement will be added straight under that statement, unless specified otherwise. The added or recorded step can either be a standard step or another conditional or loop statement (nesting).
For the purpose of our example, I will record the action of introducing a password value as the ‘Then’ part of the ‘if’ statement. The action is recorded by selecting ‘Record’ from the menu options and inputting a password value on the ‘Flights’ Login page. Take a glance at the screenshots below to see how the recorded statement is incorporated under the ‘if’ statement:
Following steps are eventually added under the ‘if…then’ block by default.
If you intend to append steps outside the block, select the block (the ‘if’ statement), right-click, and choose ‘Insert New Step after block’.
The new step will be incorporated as a sibling to the ‘if’ block.
Now that we have understood the fundamental functionality, it’s notable to remember that all other conditional statements operate in the same manner, and you can utilize any of them depending on your programming logic.
Incorporating Loop Statements into the Keyword View
To introduce a loop statement, right-click at the desired location in the Keyword View and select “Insert New Step-> Loop Statement” and pick the preferred choice.
Again, the introduced step requires to be clarified. Any recorded or added steps after the loop statement will be treated as a part of the loop block. To exit from the block, you need to expressly add a step outside the block by right-clicking on the loop statement and choosing “Insert New step after block”.
Let’s incorporate a ‘For’ statement as an instance.
I selected “For” from the menu options, and here is what gets included in the Keyword View: