Working with Keyword View – QTP Training Tutorial 2

This is a tutorial #2 in our QTP Training article series. Check out the first QTP tutorial in this training series here: Introduction to QuickTest Professional (QTP)

Introduction to QTP Keyword View

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.

Let’s start.

There is a drop-down box at the top and it shows “Action 1”.

Keyword view Action 1

What does this mean?

Introduction to Actions: 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.

For E.g.: Let’s assume that in an online web based email system, the user needs to login, compose and send email and then logout, it is recommended that each of these operations be divided into 3 different actions although all of them can be written under one action.

‘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:

QTP 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:

Dialog("Login").WinEdit("Agent Name:").Set "swati"
Dialog("Login").WinEdit("Password:").SetSecure "5112fd3c42beb7a58069b67cfdd9b7e7ad1fc69c"
Dialog("Login").WinButton("OK").Click
msgbox "text"
If x=0 Then
msgbox "text 2"
End If
Window("Flight Reservation").ActiveX("MaskEdBox").Type "010312"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("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.

This code appears as follows in the Keyword view: [click on image to enlarge]

QTP keyword view screen

------------

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.

Operations on Objects in QTP

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 is Tools->View Options and choose the required columns from the list displayed.

keyword view options

Assignment: This column is not very widely used and what this does is assigns a value to or gets a value from a variable. [click on image to enlarge]

Keyword View Assignment column

Comments: The tester can write anything under this column. It will be treated as comments in the expert view.

Conclusion:

Well, that sums up an interesting insight into the basic capabilities of the QTP keyword view. Actions are logical units of separation in a test. A test is therefore a series of function calls. When a new test is creation it contains one call to an action. By default all the actions are reusable. QTP follows a multi-level hierarchy to recognize objects. An object that contains a next level of objects is called a container. There can be more than one level of containers in a test.

In the next article we will talk about way we can use this view to Insert Steps. Modify them, Insert checkpoints, Breakpoints and how we can manage actions.

**********

This is a second post in our QTP training series started with the help of QTP expert Swati Seela. We have started this training series for those who wants to learn QTP from scratch. These tutorials are designed for beginners as well as advanced QTP testers. Join our email newsletter or RSS feed if you don’t want to miss a single article in this series.  We hope this will be the most comprehensive QTP online training for everyone.

As always help us spread the word about this valuable testing resource with your friends by sharing it on social sites . Ask your questions on this topic in below comments.

If you read this far you should probably follow us on twitter:



Get FREE eBook + Blog Updates By Email!

Subscribe to get software testing awesome articles and free resources. Enter your email address and click 'SIGN UP NOW' button.


47 comments ↓

#1 Sonal Sharma on 02.27.13 at 1:04 pm

hey thanks again for this nice article. this is really helpful for me. i wasn’t sure how to start on learning qtp but you showed us the direction

#2 Kalyan on 02.27.13 at 1:11 pm

Hi,

Thanks for the valuable info on adding Tools>> View Options >> Assignment, Comments.

A little note here.. If you are in Expert View, Tools >> View Options wont display the desired Assignment, Comments. You have to switch to Keyword View to look for Keyword View specific options.

#3 Kalyan on 02.27.13 at 1:18 pm

Hi Swathi,

I hope in coming articles you will further clarify the use of Function Libraries against the use of reusable Actions. That time please give a suitable example on when is Reusable Action is recommended over function libraries. (since using more actions in a Test causing the system performance). Forgive me if it sounds more advanced at this level.

#4 Su on 02.27.13 at 1:18 pm

Hi,

Thanks for the training. Could you explain qtp automation testing with vb script or some other scripting languages. Everywhere people are asking for scripting experience.

#5 Kapil on 02.27.13 at 1:57 pm

whats difference between keyword view and expert view?

#6 Vishwas on 02.27.13 at 5:08 pm

great…….

#7 mrunal on 02.28.13 at 2:58 am

nice…..

#8 Uma Shankar Pal on 02.28.13 at 3:41 am

Thanks Swati,

This is really a systematic way of learning QTP, however if possible let me know how to download QTP, as I tried to download it from path given in first edition, but could nt succeed, is there any other way.

Kindly explain
Thanks
umashankar

#9 Swati Seela on 03.01.13 at 1:32 am

@Kalyan: Thanks Kalyan for the pointers. Yes, the advanced topics are coming up!

#10 Swati Seela on 03.01.13 at 1:34 am

@Su: VBSCripting tutorial is in the pipeline. It takes some familiarity of the tool for you to begin programming effectively. So pls keep an eye out for the coming articles and scripting is surely going to be there.

#11 Swati Seela on 03.01.13 at 1:36 am

@kapil: Keyword and Expert views are basically different representations for your QTP test steps (the test basically has the operations that you would want to be performed on the AUT). Each view brings its own capabilities that a tester can use to his advantage. I hope this answers your answer.

#12 Swati Seela on 03.01.13 at 1:37 am

@Uma shankar: please let me know the problem you had while downloading or installing QTP Trial on your machine. I will be able to help you better if I know more information about the issue you are having.

#13 Anurag Gupta on 03.12.13 at 2:20 am

Thanks a lot Swati !
When we start recording and whatever we are doing its recorded e.g. login window activte, agent name
Can we write the script to invoke these application without its done by system?
i hope u got my pont

#14 Swati on 03.16.13 at 4:58 pm

@Anurag: Are you talking about starting the application programatically instead of using the options in the record and run settings? Yes, we can.
SystemUtil.run, InvokeApplication are some of the ways

#15 Girish on 03.26.13 at 4:54 am

Great going. Everything is very friendly for the Beginners as well as Intermediates. Thank you. Keep it going.

#16 Asha on 03.26.13 at 8:22 am

How to take the test item into the QTP,? Is there any option to load the AUT into the QTP? because you have explained only the initial settings for starting the QTP page and you have not explained how to take the test item into QTP? Please explain this also.

#17 JAYANTHI on 04.17.13 at 1:16 pm

Thankyou, its very useful, hope u r giveing more information relatted to interview and getting job.
thanks

#18 Ganesh on 04.24.13 at 11:11 am

Is it possible to work in QTP without the knowledge of VB Script?

#19 Swati on 05.12.13 at 7:37 am

@Asha: You can open your AUT in parallel and QTP can act and run on it. Or you can use QTP itself to launch your AUT.

#20 Swati on 05.12.13 at 7:38 am

@Ganesh: I would recommend at least a beginner level VB knowledge. The good news, it is not very difficult to learn.

#21 deepa on 05.16.13 at 5:40 am

Hi,
Thanks for such good article.. much helpful for beginners

#22 Kiran on 06.15.13 at 8:54 pm

Does SQL has any thing to do with QTP?

#23 Novice on 06.19.13 at 3:31 pm

Where can I find the flight sample I cant seem to locate it. I just installed the QTP 11 version.Please assist.

#24 Jing on 06.28.13 at 6:00 am

hi,

I have a problem. I have setupped QTP.It can use before, But now it cannot identify objects,why?

Can you help me?

#25 Venjay on 07.09.13 at 2:28 pm

After read all these articles i feel like wasted money and time by doing courses in training centers. They only teaching IDE and very basics..Here i have learned more than what i learnt there. Thanks for these excellent tutorials.

#26 Uday Kiran reddy on 07.09.13 at 6:07 pm

Superb Explanation…!

Thanks

#27 archana on 07.12.13 at 7:50 pm

Thank you very much for the tutorial. I downloaded QTP software but am not seeing sample flight application. Should I download it separately?

#28 Khalida Huda on 07.17.13 at 10:32 pm

I’ve installed QTP, I initaited Record and tried capturing starting from Entering the credentials in the Login Window and booked a ticket in the Flight Window. When checked for the Keyword view and Expert View all I see that it has only captured the “Flight From” and “Fly To” data.

Could you advise why it has not recorded other objects data?

#29 Khalida Huda on 07.17.13 at 10:34 pm

@Archana, Please navigate to Flight application through Start> All Programs> QTP >Sample Applications>Flight

#30 aniket kanade on 07.19.13 at 8:37 am

Hi Swati it is very nice article …. I am beginer for QTP… keep posting like this …

#31 sivaram on 07.24.13 at 5:59 am

good information about qtp,really advantage for beginers

#32 sujit on 08.31.13 at 8:06 am

very nice..

#33 chaitanya on 09.02.13 at 5:07 pm

Thank you Swathi

#34 Sarah Coleman on 09.13.13 at 3:02 pm

Excellent training tutorial! Thanks so much for your hard work putting this training together for beginners like me to learn QTP on my own.

#35 suresh on 11.08.13 at 12:47 pm

hi

#36 Dhananjay on 11.17.13 at 5:46 pm

Hi Swati & Vijay , I got some queries about If….Then statement to use in QTP . While doing some handson i found i was unbale to set correct scripts to execute the Test. Hence i approached you through this Comment. Please revert me soon.

#37 Raghavendra on 11.20.13 at 2:15 am

Hi Swathi and Vijay, Excellent training tutorial! Thanks so much for your hard work putting this training together for beginners like me to learn QTP on my own.

#38 Raghavendra on 11.20.13 at 2:18 am

Hi swathi and Vijay, i have small query in QTP11.5 version.

Where i can see the tab on the screen. I got the Keyword view but not expert view. Thanks

#39 swetha on 12.04.13 at 4:04 am

Hi swati and vijay,

QTP tutorial is really good. please could any provide similar kind of tutorial for sahi or selenium ?

Regards,
Swetha

#40 Chandan Mohapatra on 12.10.13 at 12:16 pm

Hi Swati,
Thanks for your excellent Traing Tutorial, But if you will give some more example, then this would be thorough about that.

Thanks,

Chandan

#41 Hema on 12.11.13 at 3:54 pm

Hi,
Thanks for your training materials , I am a beginner and this has been a great help . Thank you .

#42 madhulatha on 12.30.13 at 12:43 pm

THanks for the information…i am a fresher in QTP.

#43 Hameetha on 01.22.14 at 9:55 am

I am not able to find the flight application that comes with the UFT . Where should i look for it.

#44 dangod on 02.11.14 at 5:17 pm

Anyone want to share downloaded QTP 10 or 11 or a link for them appreciated.

#45 jyoti on 02.26.14 at 9:03 pm

I am B.com graduate. Want to get into the IT field. Want to learn QA testing and its tools. This is one of the best explained and described website , thank you very much for uploading. Pls guide me how to get started wih the QA testing .. what I should know , since my education background is comerce. what are the best tools I should be knowing pls guide me.

thank you,

#46 Renuk on 03.05.14 at 6:33 am

Hi Vijay,
QTP tutorial is very usefull,Thanks for posting .I have some interview questions ,i would like to ask now.

1.If there are more than 1000 defects in an application.The timing provided for this application testing is just one week,so how will you perform?

2.How will you write a test cases for a page ,in which say 8 to 9 fields or objects are there?

These are my questions vijay.can you reply

Regards
Renuka

#47 Sanjay on 03.25.14 at 9:39 am

One doubt whether we can use checkpoints for web application?