Descriptive Programming in QTP – Part 3

Hello friends!

In Part-1 and Part-2 of this post, we learned type of DP and how to use DP. In this part, we’ll cover –

– Using childobjects
– Using GetROProperty

Childobjects and Getroproperty are two most commonly used and i think most useful methods for DP.

Life is easy while working on a stable application where objects are not changing dynamically. But imagine the situation where there are only one or two properties found by QTP for a particular object, and these are also not constant!!

Childobjects may save your day!! Yess!!

You can do a lot using Childobjects and Getroproperty. Lets start with simple things in this post.


Childobjects:

Childobjects the collection of child objects contained within particular object.

Means???

Okey. Consider the below screen –

This is a Login dialog, contain few other object i.e. Agent name, password, buttons.
In this case Login Dialog is parent and Agent name, password, buttons are child objects.

How to use Childobjects method:

Suppose you have a page which gives you few options, i.e. Individual and Corporate. If you select 1st, on next page, you will see few fields like name, passport no, age, sex etc. But if you choose 2nd, you will see name, registration no, type of business etc.

Means page will be change on the basis of selection. Suppose you have 50 options, so you’ll be having 50 different pages, all with different number/type of objects. You don’t know how many objects will be there on any page.

Now you need to count the number of buttons on a particular screen, or, let’s say number of links on a web page. How to do that?

And the answer is.. using childobjects method!!


Open the above window – Start>>Program>>QuickTest ProfessionalSample Applicationsflight.exe>>Login into application, and run the following code in QTP..

Set oDesc=Description.Create()
Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of objects: “&cnt
For i=0 to cnt-1
      Print “Class: “&oAll(i).GetROproperty(“micclass”)&”, Text: “&oAll(i).GetROproperty(“text”)
Next

Above code will give you the number of objects on window. You can provide more specific description. Suppose you need to enter some value in all the textboxes on the page. You don’t know how many textboxes are there on page. Run following code..

Set oDesc=Description.Create()
oDesc(“micclass”).value=”WinEdit”

Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of EditBox: “&cnt
For i=0 to cnt-1
    If  oAll(i).Getroproperty(“enabled”) Then
        oAll(i).Set “Editbox:”&i
    End If
Next

Here oAll is an array which contain all the textboxes and it’s index starts from zero. So if there are total 9 textboxes on window, array index will be oAll(0) to oAll(8).

Following is one more example. You have to click on particular button (if it displayed on the page). t might come or not..

Set oDesc=Description.Create()
oDesc(“micclass”).value=”WinButton”

Set oAll=Window(“text:=Flight Reservation”).ChildObjects(oDesc)
cnt=oAll.count
Print “Total number of Buttons: “&cnt
For i=0 to cnt-1
    If  oAll(i).Getroproperty(“text”)=”FLIGHT” Then
        oAll(i).Click
    End If
Next

I was working on a application, where you need to work on two instances of the application at the same time.(1st as customer and 2nd as trader). All properties are same because application is exactly same. In that type of situations, childobjects is the way you can survive upon!!

So it was starting learning advanced DP uses. Explore above codes and try to get good understanding of childobjects and getroproperty methods.

In next part of this post we’ll cover more advanced stuff of DP.

In case of any queries, please post your comments. Happy QTPing…!!

12 thoughts on “Descriptive Programming in QTP – Part 3”

  1. Ankur Jindal

    Jain Sahib, i really don't have any idea about QTP but there is a small observation:
    in the very first example, you used oDesc in the second line but you didn't assign any property/value to this object. So, how it will work?

  2. @Ankur

    see these lines carefully..

    Set oDesc=Description.Create()
    Set oAll=Window("text:=Flight Reservation").ChildObjects(oDesc)

    oDesc is just a blank object, which is passed to oAll. oAll will have all the objects.

  3. Hi Abhikansh first i would like to thank u for ur posts, its very help full and clear, could u explain me the following statement how it works, GetROproperty is used to get the property of the object but why we are using it for the second time.

    Print "Class: "&oAll(i).GetROproperty("micclass")&", Text: "&oAll(i).GetROproperty("text")

    and why we are giving "k=i+2" in the first example in the for statement.

  4. Hi Abhishek,
    Thanks for posting this good article.My question is,suppose we have 6 Editbox with the same property on a page. I want to enter the data into the 4th box.I have some idea that index will be used in that case but how to write the code with that index. Could you please explain?

  5. Hi Abhi is it mandatory know the scripting for learning QTP. Because past 2+ years i am working as manual tester,so i am new to the tool. If VBS is mandatory which are the main key areas i have to concentrate. Please list out the topics.

    @Bangalore

  6. Can you Please share a complete example illustrating how to automate a page,,say irctc just show how to login ,search a train and click on book.Please show how to use wait statement also in this in this example
    Also could you please explain what are the associated library functions in QTP and how to use it.

    Thanks in advance !

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top