My Blog List

Wednesday, November 2, 2011

Custom functions to Override Standard Operations - QTP


Hi all,

Here I am going to talk about a nice feature in QTP. Generally we might require the operations such as click, Set, etc which should not stop the script if it fails on that particular step.
Also some different way we have simulate the operations for different type of objects. ie. We may need custom functions for click, set etc.

Here is the example.

''This is my function which will do repeative typing
Function MySetRepeat(test_object, TextToSet)
   test_object.Set( TextToSet + TextToSet)
End Function

''This line is used to register the above written custom function for type of objects.
''1st Parameter: Class/Type of object
''2nd Parameter: Function name to call for the test objects
''3rd Parameter: Actual function name you wrote
''4th Parameter: Set as default function or not
RegisterUserFunc "WebEdit", "SetRepeat", "MySetRepeat",True


So, now I am using my function in my script as follows.
Browser("Title:=google.*").Page("Title:=google.*").Sync
Browser("Title:=google.*").Page("Title:=google.*").WebEdit("name:=q").SetRepeat "testing"

Now, it will set the given text 2 times....





1 comment:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete