Showing posts with label Vista. Show all posts
Showing posts with label Vista. Show all posts

Activate, Maximize, Restore and Minimize a Browser - Part 2


Here we are in Part 2 of this discussion. Please make sure you have gone through Part 1 before you continue further.
What we saw earlier was that it was possible to activate, maximize, restore and minimize a Browser. We did this because the Browser object did not have the Activate, Maximize, Minimize and Restore methods. However we could do something more interesting by actually creating these methods for the Browser object. This is accomplished through a utility statement in QTP called as "RegisterUserFunc".

Description:
Enables you to add new methods to test objects or change the behavior of an existing test object method during a run session.

Sometimes its interesting that QTP Help documentation gives detailed description on how a particular utility works but does not give a "practical" example. Lets not get into that.
RegisterUserFunc can actually do two things. Create a totally new method for an object or override an existing method. In our case, we are going to create a new method for the Browser object. So lets see how we are going to do that.



Voila !!!! We have now created a new method called Activate for the browser. You could also put the above function definition and RegisterUserFunc statement within a function library for more efficient handling of your resources. In a similar way, we could also go ahead and create the remaining functions for Maximize, Restore and Minimize and Register all these functions with the Browser object as below

RegisterUserFunc "Browser", "Maximize", "Maximize"
RegisterUserFunc "Browser", "Minimize", "Minimize"
RegisterUserFunc "Browser", "Restore", "Restore"

Well, we just saw a pratical example of RegisterUserFunc and also how to make use of this feature in our Browser object.

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!

As always,

Your friend in need,


George, Reju

Read Users' Comments (0)

Activate, Maximize, Restore and Minimize a Browser - Part 1



Have you ever had the need to activate, maximize or minimze a browser ? I am sure you had...but unfortunately the Browser object does not have these methods. So what do we do. I have faced this situation and so wanted to share what I did to accomplish this.
What we will do here is use two concepts. Descriptive Programming and Registering a function with an object which would make our code very neat.
The very first step with this approach is that we would be identifying a Browser object as a Window instead of a Browser. For the Windows operating system, after all, everything is a window. So we will make use of some properties within the Window object to recognize a browser. I had already covered this in another thread on QTP 10, Vista and IE8 where we do this.
OK. Before that lets understand one thing. Every window has a property called as "handle" and this is unique for each and every window. In QTP, this property is known as "hwnd". So a Browser window can also be identified with a Window Class object if we pass the handle. Open any browser and then spy on it. Get the window handle. Lets say its value is 459420. Now this browser can be identified as Window("hwnd:=459420"). So we are almost there. Since a Window object has the methods Activate, Maximize, Restore and Minimize methods, we could make use of them over here... isnt that interesting !!!!



Our code looks like above. Using the "hwnd" property is the best way to identify the browser because it is unique. However you could also make use of the "nativeclass" and "regexpwndtitle" properties which would be "IEFrame" and "Windows Internet Explorer" respectively.

Window("regexpwndtitle:=Windows Internet Explorer","nativeclass:=IEFrame").Activate

But the above code would not work when you have multiple browsers open. Thats the reason why I mentioned earlier that getting the "handle" of the window is the best technique.
So here we just showed that we could activate, maximize, restore and minimize a Browser as well !!!! Continue to read Part 2 on this topic. Enjoy the journey !!!!!

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (0)

QTP 10, Vista and IE8

If your question is whether QTP 10 supports IE8 on Vista, the answer is "Yes". At least, thats what HP QuickTest Professional 10.00 Patch QTPWEB_00037 Readme File says. The documentation also says
"This patch provides official support for testing Web applications in Internet Explorer 8.
It includes support for working with Internet Explorer 8 on all operating systems that QuickTest Professional supports."
QTP 10 supports Vista, so this also means that IE 8 on Vista is supported. However not everything looks rosy here because when I try to spy on IE8 in Vista....this is what I see..




QTP recognizes the browser as a Window object instead of Browser. Now this is not always the case. In some cases (for which I have no explanation) it does recognize IE8 as a Browser object. So I would be reluctant in stating that QTP 10 supports IE8 on Vista "completely" !!!!!

All that said and done, let me get into the reason why I wanted to write this article. I had got stuck with a problem where I wanted to activate a browser. I am sure you would also have known by this time that you activate a browser by getting the handle of the browser and then do a Window("hwnd:=" & hwnd).Activate. Well, lets try it here...but before that we have a sort of chicken and egg problem here... if we are unable to recognize the browser then how do we get its handle !!! One way is to use the object spy on the browser and get the handle... the other way is by knowing that the regexpwndtitle property of such a window would be "Windows Internet Explorer" and nativeclass property would be "IEFrame" and another way would be to use Description objects. Lets use the properties here ..

wHandle = Window("regexpwndtitle:=Windows Internet Explorer", "nativeclass:=IEFrame").GetROProperty("hwnd")
Window("hwnd:=" & wHandle).Activate
There you go ... it worked !!!
Just make sure that if your browser is in "Full Screen" mode, the Activate method would not work so make use of the "Click" method instead of Activate.
I hope this saved you time "googling" further for this problem and you got a resolution.

Update: Oh boy !!! Why didn't I know this earlier ?? Just figured out why IE8 was not being recognized as a browser in Vista. I usually work on Vista as a standard user and have my UAC (User Access Control) set to "ON". This is because it gives an added security and gives you more control over unauthorized access on your system. For some reason, I had to uncheck the UAC option. Of course, you can do this only as a user with administrative privileges. And Voila .... QTP started to recognize IE 8 as a browser with absolutely no problems. Now is this problem only on IE8. Not really !! I downgraded my IE8 to IE7 but still it was being recognized as a Window. So all this while, UAC was the culprit. OK...so things are resolved, but I would want to test on Vista with the UAC set to ON !! H-m-m... will investigate further and let you know if there is any solution.

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (5)

Visitors

Website Counter