Relevant Codes (by Anshoo Arora)

A Test Development Resource for HP QuickTest Professional.

Browser: Not Required!

by Anshoo Arora on May 2, 2010

This has been tested to work correctly on QTP versions: 9.5+.

There is a common perception that we must include the Browser object in hierarchies when working in the Web environment. The truth is that, we really don’t need to include the Browser object if the Page object has been included in the hierarchy.

In other words, the commonly written inline statements for Web environment:

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Set "Test"
Browser("title:=Google").WebEdit("name:=q").Set "Test"

can also be written like this:

Page("title:=Google").WebEdit("name:=q").Set "Test"

Quick tip! Thanks for visiting Relevant Codes! :)

{ 30 comments… read them below or add one }

1 SatishKumarDega May 3, 2010 at 11:34 pm

Hi ,
I need ur help I am going to attend for first time testing interview I nedd some good interview questions manual and automation and QTP.
Could you please provide me suggestion and give some real time senarios what are the questions they in QTP.
Please do the needfull regarding this.

Reply

2 Anshoo Arora May 6, 2010 at 2:05 pm

Satish,

I really hope your interview goes well!

I’m sorry, but this is an area where my advise can prove to be more harmful than helpful. The interviewer can ask anything depending upon their environment, technologies and release schedules.

3 Harish May 5, 2010 at 5:33 am

Page(“title:=Google”).WebEdit(“name:=q”).Set “Test”

If I use this statement I got a error message as,

Cannot find the “[ WebEdit ]” object’s parent “[ Page ]” (class Page). Verify that parent properties match an object currently displayed in your application.

Do you I need to do any settings?

Reply

4 Anshoo Arora May 5, 2010 at 7:52 am

Hi Harish,

The above code is working fine for me.. Can you make sure you do not have more than 1 browser with the same properties open?

5 Anshoo Arora May 6, 2010 at 2:09 pm

Harish, any luck having this work on version 9.2? I have included a small note in this post regarding version compatibility.

6 Dennis May 10, 2010 at 5:41 am

Hi, Anshoo,

I remember I can write as this

Browser("title:=Google").WebEdit("name:=q").Set "Test"

I suppose your perception can working well, so why the “Page(“title:=Google”)” is required?

Can I understand it as we need to indicate at least one specific container for the web element? So we can write as

Browser("title:=Google").WebEdit("name:=q").Set "Test"

and also

Page("title:=Google").WebEdit("name:=q").Set "Test"

Am I right?

Regards,
Dennis

Reply

7 Anshoo Arora May 10, 2010 at 10:26 am

Absolutely :)

There is one thing though. When using ChildObjects, you must include the Page object otherwise the count will be incorrect. In other words:

Set oDesc = Description.Create

'Will give 1 because it has only one childobject, which is the Page object
MsgBox Browser("title:=Find.*").ChildObjects(oDesc).Count
MsgBox Page("title:=Find.*").ChildObjects(oDesc).Count

Reply

8 Shekhar1809 June 21, 2010 at 7:12 am

Hi , i want the qtp scripts for below scenarios,plz do needfull

1.I have two buttons which are rotating in clockwise direction in page . i need qtp script two click on second button.
2. i have a weblist where i can select multiple items using Ctrl , i need qtp script to select any four items among the available 10 items.

Reply

9 Anshoo Arora June 22, 2010 at 12:35 pm

Hi Shekhar,

1. If these are the same buttons with the exact same properties, then regardless of their movement on the screen, you can use the Index/Location identifiers to distinguish between them. The first button will be Index 0, the second one will be Index 1. Example:

'Button 1
.WebButton("name:=Button", "index:=0").Click

'Button 2
.WebButton("name:=Button", "index:=1").Click

2. You can use the ExtendSelect method to perform this.

10 Handling Flash components through QTP...? June 21, 2010 at 8:35 am

Hi Anshoo,

I was stuck up in choosing the correct automation tool for automating web based application (developed using Flash components). QTP recognizes the whole window as a single object, instead of individuals (where some internal components also reside in it). Is there any way(by exposing any API’s or so to the source) where we can make the QTP to recognize such objects…
Else can you please suggest me the best automation tool which can solve my problem (Automating the customized flash components…)

Regards,
Venkat…

Reply

11 Anshoo Arora June 22, 2010 at 12:37 pm

Hi Venkat,

I haven’t had much experience automating Flex/Flash applications but I do know that there are some limitations with this. Please see this article: http://livedocs.adobe.com/flex/3/testing_with_QTP_flex3.pdf

It does cover some of the limitations.. Not sure what the best automation tool would be though. :(

12 Shekhar1809 June 22, 2010 at 11:44 pm

Hi Anshoo,
Thanks a lot for your quick reply, and thanks a lot for sharing your experience with us thru this blog and this blog is very usefull to guys like me.Gr8 work , i wish and hope to continue the same.

and i have one more question in my mind,
i have a webtable like below.

AccountNo AccName Balance
100 shekhar 10000
A100 Chandra 2000
100a Guttikonda 500
A100a Chandrashe 5000

Now my query is i want to get the rowcount whose accountno starts with 100.By phiscally seeing the row count 2 and i want to get the same rowcount with qtp script

Reply

13 Anshoo Arora June 28, 2010 at 10:19 am

Shekhar,

You can use the GetCellData method of the WebTable to retrieve cell values. Example:

iRows = Browser("").Page("").WebTable("").GetROProperty("rows")
iCols = Browser("").Page("").WebTable("").GetROProperty("cols")

For ix = 1 to iRows
	For iy = 1 to iCols
		If Browser("").Page("").WebTable("").GetCellData(ix, iy) = 100
			Print "Data found on Row: " & ix & " and Column: " & iy
		End If
	Next
Next

14 Vasanth June 23, 2010 at 2:21 pm

I was stuck up in choosing the correct automation tool for automating web based application (developed using Flash components). QTP recognizes the whole window as a single object, instead of individuals (where some internal components also reside in it). Is there any way(by exposing any API’s or so to the source) where we can make the QTP to recognize such objects…
Else can you please suggest me the best automation tool which can solve my problem (Automating the customized flash components…)

Regards,
Venkat

For testing a flash/flex application you need flex addin and your flex application has to be compiled with automation library or call the application in html wrapper. here is the doc which tells you how to do installation http://www.adobe.com/support/documentation/en/flex/2/install.html
Let me know if you need more info….

-Vasanth

Reply

15 Anonymous June 25, 2010 at 6:17 am

Thanks a lot Vasanth.. I will go through the links you have provided..will get back to you if I fins any obstacles in my path…Thanks a lot once againnnnn

16 mahesh December 13, 2011 at 5:27 am

hello vasanth,

with referance to your post I can understand that qtp supports flex. However, I would like to make sure that whether qtp suppors flash or not.

17 Jenny July 1, 2010 at 12:22 pm

Thats a fantastic article Anshoo.. I really like your website.

Jenny

Reply

18 tester July 14, 2010 at 8:14 am

Hi Anshoo,

I am facing a problem. I am automating a web application. I am using set of properties to identify the object. But for each build the property values are changing. Development team is not ready to keep the fixed standard property values as per the requirement.
How can I handle these scenarios.

Reply

19 Anshoo Arora July 14, 2010 at 3:22 pm

Generally, I try to educate my clients to not start automating on a grand scale until the application has reached a point of stability. Its always a nightmare to automate applications that are constantly changing, or are in constant development that either impact the test fields or the business process.

There are however dynamic applications, which are generally a challenge to automate but there are numerous ways to handle such scenarios. However, yours being the former case, I’m afraid you will face some maintenance issues every now and then because tests are generally basic on the application’s flow and any change to that causes tests to fail.

20 Niranjan December 21, 2010 at 12:09 am

Hi Anshu,

Why it is possible for the QTP to skip the Browser/Page object in web inline statement? Is it that they are not mandatory for each other in the web test objects?

regards
Niranjan

Reply

21 shashank December 30, 2010 at 3:19 am

Hai Anshoo,

Your mind goes brilliant in QTP

I am a Great Fan of yours………

I want to tell you one Thing
I am your permanent Member of relevant codes……

“Bus Yuhi Chalte Rehna…”

Reply

22 kumar June 4, 2011 at 9:04 am

hi anhoo please tell me i have one doubt if we want to check whether the web paage has all the contents or not i..e if any web page has only checkboxes then we have to check all the checkboxes are available or not we dont know how many are there please tell me

Reply

23 Anshoo Arora June 24, 2011 at 10:37 am

Kumar: This can be done through ChildObjects. Please see here: http://relevantcodes.com/qtp-all-about-the-description-object-description-create/

24 kumar July 3, 2011 at 9:35 pm

hi thanks a lot for your response currently iam handling a new project with .Net windows environment can we follow the same process please guide me & give me some basics related to that thank you

Reply

25 Shailesh August 4, 2011 at 4:38 am

I guess this works only with the DP. with normal OR approach its of no use..
Any ways good post.. :)

Reply

26 Anish 10110 September 12, 2011 at 9:00 am

Anshoo,
Another Gem of an article.. I wonder how you get to know all these things.. :) But i guess Browser object would help in organizing the repository in case we have to deal with multiple browsers/pages. What’s your thought on this?

@Shailesh,
I have tried to use the same logic in OR also. It works perfectly fine.. :)

Reply

27 Anshoo Arora September 12, 2011 at 10:25 pm

Just want to say here that in case you’re using .ChildObjects here, remember to add a Page object. ChildObjects will return 0 if Page is not added.

28 Venkat June 25, 2010 at 6:33 am

Thanks a lot Anshooo

Reply

29 Shekhar1809 June 30, 2010 at 5:17 am

Hi Anshoo,

Thanks for the code..
But the code ur suggesting is ..that everycell value is equating to 100.
but i need the count of the rows whose account is starting with 100.
how can achive it.

Reply

30 Anshoo Arora July 6, 2010 at 9:19 pm

You will have to change that code and use InStr instead then..

Reply

Leave a Comment

Previous post:

Next post: