QTP Descriptive Programming - How to perform operations on objects?

QTP Descriptive Programming - How to perform operations on objects?

In previous QTP tutorial (QTP Descriptive Programming - How to get number of objects) I explained how to get number of objects (Edits, Links, Buttons) with QTP Descriptive Programming (QTP DP).

Today I'm going to show:
How to use QTP DP to perform different operations on objects.

For example, how to type text in these edit boxes on Google Sets page:
QTP DP - How to type in edit boxes?
From previous QTP DP tutorial you know that this code returns a collection of Edits located on Web page:
Set Desc = Description.Create()
Desc("micClass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)


So, to type text in each Edit, we have to process edit boxes
from returned collection one by one.
We can access the specified item from a collection by item's index.

For example, the following code types a text in the first edit box:

Edits(0).Set("Text in Edit #1")
And its result is:
QTP DP - Firt EditNote: ChildObjects returns zero-based collection of found objects.
That's why use Edits(0) to access first item, Edits(1) to access second item, and so on.


So, we add a loop to process all edit boxes on a page.
The final QTP script is:
Set Desc = Description.Create()
Desc("micClass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)


NumberOfItems = Edits.Count
For i = 0 To NumberOfItems - 1
    Edits(i).Set("Text in Edit #" & (i+1))
Next

This code fills all Edits in. So, the result page looks like:
Result of QTP DPAs you can see - QuickTest Professional Descriptive Programming works correctly.


Note: If the initial page contains more (i.e. 8) or less (i.e. 3) number of edit boxes, our QTP script will work without changes!

Note: Since we do not use QTP Object Repository (QTP OR), this approach can be integrated easily into any existing QTP system. Shared
Object Repository is not required!


Summary:
The article shows how to perform operations on objects.
The approach uses QuickTest Professional Descriptive Programming.



Related articles:


Do you like this QTP tutorial? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)



13 comments:

Anonymous said...

Hi Dmitry,

I am so happy to find this blog which gives important information about QTP.I have a request, could you please show a video on how to use smart identification feature in QTP.

Thanks for your efforts.

Dmitry Motevich said...

Anonymous,
Please motivate me to spend ~20-30 hours and prepare this video :)

Anonymous said...

hi,
i found this blog to be very interesting and informative for upcoming professionals

Anonymous said...

Really good examples!!! Many thanks for sharing with us...

One question about the way objects work when pass from one Test-Action to a library.qfl?

I've defined an URL_obj in my test as:

Set url = Browser("name:=real_name").Page("title:=real_title")

then I call a function within an external library with:

call library_function(url)

and then if I try to use that object in the normal way for doing simple stuff, such as:

url.Link("text:=real_text")

I receive the following error:
'Object doesn't support this property or method: 'url.Link'

Is it possible to do something like that? It works if you declare a new Link object just for invoking it, but this is kind of a pain in the ass if you need to do it too often!! Not sure if I'm missing something...


Set link_obj = description.Create()

link_obj("micclass").Value = "Link"

link_obj("text").Value = "real_name"

Set nOccur_link_obj = url.childobjects(link_obj)

nOccur_link_obj(0).Click

Anonymous said...

Thanks for the article!! Keep the good work...

Dmitry Motevich said...

1. It seems, that the following libe is not executed:
Set url = Browser("name:=real_name").Page("title:=real_title")
Please check it
2. What does library_function do?

Anonymous said...

If you call the subroutine, I'm getting the same error message.

Dmitry Motevich said...

to Anonymous (September 27),
And what?

Swami.SP said...

Hi Dmitry...

Your blogs are good....
thanks for sharing many useful things....

Thanks,
Swami

Anonymous said...

Hi Dmitry,
Thank you very much for sharing your thoughts with us. The videos are amazing. I have learned so many things from your blog which clarified my doubts. could you please provide information about frame works. I have one question, who prepares the frame works for QTP means tester or sr.test engineers or managers.
Thank you.

Anonymous said...

Hi,

Really interesting and learning from this site, how to write the scripts in QTP.

But I have a small question: can we pass unique values for these test boxes?

Unknown said...

Hi Dmitry Motevich

Thanks for providing video.Really Useful.
One question that i need to ask is how we identify dynamic objects through smart identification.
I mean to say i need to know the diference in smart identification & Descriptive programming.

Would be great if you can clear out this confusion.

Many Thanks
Nancy

Rakesh said...

HI,
I found this site very very helpful in Learning QTP. In fact I will recommend my friends also to visit and learn more - Rakesh