QTP GUI introduction

This article is going to give you an insight into the Keyword view of the QTP GUI. During this process we are going to get a quick introduction to Actions, Object Hierarchy and the basic columns in the keyword view.
Step1: Run QTP
Tests in QTP are recorded in terms of actions. Action is nothing but a set of statements performing a sequence of actions.  Most often an action is simply a logical unit of modularity. The calls to one or more actions can be defined as a QTP test.





‘Test Email’ will have:
Action1>Login
Action2>Compose and send email
Action 3>Logout
The Test is essentially:
Call to Action1; Call to Action 2; Call to Action 3
If written in one action, the lines of script would be large and difficult to manipulate and maintain. So the logical division is recommended. Also, as we move on further in our exploration about Actions we are going to understand how actions can be parameterized thus enabling easy repetition of a certain action as many times as desired.
So when you create a new QTP test it contains a call to one action, “Action 1”.
When we expand the drop down, it shows the Test Flow. For a test with multiple actions it shows the sequence in which each action is called thus making the name, “Test Flow” self explanatory. This drop-down not only displays the sequence of actions, it also provides the option for the user to select or go-to a particular action to view and/or Edit.
There is also a “Reusable Actions” Folder view. For now, let’s just say that reusable actions can be used by multiple tests and multiple times in the same test where it was created. We are going to discuss in detail how that can be achieved. Every action by default is reusable. This can be changed if need be.
Let’s take a little diversion here and talk a little bit about Object recognition hierarchy in QTP.
Object Hierarchy – If you have noticed in our example the Agent Name and Password are displayed under the item Login. A point to note here is that, QTP uses a tree hierarchy to store objects. In our case, the Agent Name and Password are the child objects to the container object Login which is the Dialog. Container objects are window, dialog box in a windows based environment and web page in a web based environment.
Here is an example, the login Dialog of the flights application:

The container here is the Login dialog and next level objects are Agent name, Password and the other buttons and images in the dialog. There are only 2 levels here. But there could be more levels, like browser.page.button in this case, browser is a container for page and page is a container for button.

Working with Keyword view:

I am going to use the test we recorded in the previous article. Opening the flights application. Entering the Agent Name and Password in the Login Page and Clicking on OK.
I am also going to add some function calls and statements to programmatically from Expert view and show you how they appear under the tabular form in the Keyword view.
This is the code I put in the expert view:
1Dialog("Login").WinEdit("Agent Name:").Set "swati"
2Dialog("Login").WinEdit("Password:").SetSecure"5112fd3c42beb7a58069b67cfdd9b7e7ad1fc69c"
3Dialog("Login").WinButton("OK").Click
4msgbox "text"
5If x=0 Then
6msgbox "text 2"
7End If
8Window("Flight Reservation").ActiveX("MaskEdBox").Type"010312"
9Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
10Window("Flight Reservation").WinComboBox("Fly To:").Select"Frankfurt"
Lines 1 through 3 are the login operation. Line 4 is a function call to message box display operation. The I added a dummy if statement just to show you how it appears in the keyword view. X is a dummy value as well. Since we are not going to run this test, let’s just use it theoretically. Lines 8 through 10 are entering the date of flight and to, from locations. This is used to understand how objects are grouped.
As you can see there are 4 columns- Item, Operation, Value and Documentation. The table can be expanded or collapsed by clicking on the little arrow next to the action name.
Item: Each step is a sequence of events performed on an item. The item can be one of the following:
  1. Test object (e.g.: Agent Name Edit box)
  2. Utility Object: These are some objects reserved by QTP to be used in tests. E.g.: DataTable object. More coming up on this later.
  3. Statement: Any VB Script programmatic statement or even comments
  4. Function call: like ‘msgbox’ call in our program
Operation: It shows the operation that is performed on the item. When this column is clicked for a particular item it lists all the available operations that can be performed on the object.

Value: This column can be considered as the argument of a statement displayed. In our example, the message box function call has a value “Text”. There can be multiple arguments to one statement in which case this column will be divided accordingly.
Documentation:  A read only column that translates a statement into easily understandable comments.
There are two other columns Assignment and Comment that can be added to the Keyword view table. To do so, the option to select isTools->View Options and choose the required columns from the list displayed.

Assignment: This column is not very widely used and what this does is assigns a value to or gets a value from a variable



translate

Hôm nay đọc gì

Lưu trữ

view

view