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)

Visitors

Website Counter