QTP Wonder codes some Functions

Function Login(username, password)
                    oUserTxt.Set username
                    oUserPwd.Set Ucase(password)
End Function
ExecuteFile PathFinder.Locate("LoginUpdate.vbs")
Associated library
Function NewMsgBox(Message)
                    Print "The user says – " & Message
End Function

Dim fnPtrNewMsgBox
Set fnPtrNewMsgBox = GetRef("NewMsgBox")
Action Code
Dim MsgBox

Set MsgBox = fnPtrNewMsgBox

Msgbox "Tarun"
The advantage of this approach is that we can use the original MsgBox function as well in the NewMsgBox method which was not possible with the earlier approach
orkaround to that I decided to use a new ActualParams objects. So the Library was updated as
Dim ActualParams

'By default we will use the component parameters
Set ActualParams = Parameter

Function App_Login()
                    Browser("X").Page("X").WebEdit("UserName").Set ActualParams("UserName")
                    Browser("X").Page("X").WebEdit("Password").Set ActualParams("Password")
End Function
Now I can use the function as below in my component
'Call with component parameter
Call App_Login

Dim DummyParams
Set DummyParams = CreateObject("Scripting.Dictionary")
DummyParams("UserName") = "Tarun"
DummyParams("Password") = "Tarun"

'Set the Actual parameters be used in Function as DummyParams
Set ActualParams = DummyParams
Call App_Login

'Rest of the functions to use the component parameters
Set ActualParams = Parameter

Post a Comment


Close Menu