I'm working with HP UFT. This tool use VBScript to automatics test. Is it possible to create new method in function library. I mean something like this.
Browser("Browser").Page("Page").WebEdit("login").MyMethod()
How can I do that?
Adding User Defined Functions is actually pretty easy: define the function, decide on the object type you wish to add the function to, and use RegisterUserFunc to put it all together:
Function BrokenImage(ImageObject)
BrokenImage = True
ImageObject.WaitProperty "visible", True, 1000
ImageLoaded = False
StartTime = Now()
Do
If ImageObject.Object.naturalHeight > 0 And ImageObject.Object.naturalHeight > 0 Then
BrokenImage = False
Exit Do
End If
If DateDiff("s", StartTime, Now()) > 10 Then Exit Do
Loop While ImageLoaded = False
End Function
RegisterUserFunc "Image", "BrokenImage", "BrokenImage"
Once you've got the function defined, you call it as you would any other object method:
If Browser().Page().Image().ImageBroken() = true Then Print "Broken Image"
You can also add additional parameters which will then be passed to the new method.
Go to the Design menu, and select Function Definition Generator... You'll get the following UI
Basically this is a helper for
RegisterUserFunc
.By selecting the Register to a test object check-box (and which type of test object) the function you add will be available as a regular test object function.
Note that you can override an existing function, for example you can change
Set
to see if the value is"~today~"
add today's date.