Interview Questions   Tutorials   Discussions   Programs   Videos   

QTP - What is the use of "Registeruserfunc" when should we use it?

asked marvit August 29, 2014 08:35 AM  

What is the use of "Registeruserfunc" when should we use it?


1 Answers

answered By Dharma   0  
This object is used to add new methods to a test object or to override existing ones. The syntax is

RegisterUserFunc TOClass, Method, FunctionName, SetAsDefault

If we want to override the SetFunction for WebEdit test object then we need to create a new function and then assign it using the RegisterUserFunc object as follows:

'New set method for webEdit objects
Sub NewSet(Object , newValue)
  Object.Set Ucase(newValue)
End Sub

RegisterUserFunc "WebEdit", "Set", "NewSet"
Browser("Browser").Page("Page").WebEdit("Text").Set "Nikhil"

The last statement in our example now calls out NewSet function and changes the input value
to upper case and then assign the value.

If we want to use the NewSet function to handle different types of test objects, then we can use GetTOProperty function to determine which type of object has been passed to the funtion.

If we want define a new Set method for all the objects like "WebEdit", WebCheckBox", WebList", "WebRadioButton" etc, then we can create a function like one shown below:

'Generic set method for various objects
Sub GenericSet(Object, newValue)

  'Get the type of the object
  sObjectType = Object.GetTOProperty("micclass")

  Select Case sObjectType
    Case "WebEdit", "WebCheckBox"
      WebSet Object, newValue

    Case "WebList", WebRadioButton"
      WebSelect Object.newValue
  End Select
End Sub
   add comment

Your answer

Join with account you already have



 Write A Tutorials
Online-Classroom Classes

  1 person following this question

  1 person following this tag

  Question tags

qtp × 1

Asked 4 years and 2 months ago ago
Number of Views -254
Number of Answers -1
Last updated
4 years and 22 days ago ago

  Similar questions

Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!