Executing Code In Local Scope From with in Global scope - QTP

We earlier saw how to load library files in local scope from within the local scope ("Dynamically L oading libraries locally at run-time") and how to load libraries in global scope from within local sjope ("Dynamically Loading libraries globally at run-time").

At times, because of script maintenance we might need to add code to the start or the end of the Action. This maintenance might apply to multiple no. of scripts. QTP allows opening single script at a time, which makes editing multiple scripts a time consuming task. To avoid such situations we can c ill two special functions in our Actions as shown the following code

'Evaluate any code that needs to be executed at
'thestart of this Action
ExecuteGetAction5tart()
Code tealted to Action
'Execute any code that needs to be executed at
'the end of this Action
Execute GetActionEnd()

GetActionStart and GetActionEnd function return either a blank string of some code that needs to be executed. Below is the implementation of the above two functions

'Function to be called at start of each action
'this function will allow dynamic execution of
'code in local scope of the action, function should
'be called in the below format at the start of action
'Execute GetActionStart()
Function GetActionStart()
'By default no code to be executed
GetActionStart = ""
'Get the name of the Action which called this function
sAction =LCase(Environment(""ActionName"))
If InStr(sAction,"main") Then
GetActionStart ="ExecuteFilePathfinder.Locate(""Workaround.vbs""}
" End If
End Function
'Function to be called at end of each action
'this function will allow dynamic execution of
'code in local scope of the action. Function should
'be called in the below format at the start of action
'Execute GetActionEnd()
Function GetActionEnd()
'By default no code to be executed
GetActionEnd = ""
'Get the name of the action which call the script
sAction = Environment (""ActionName"")
End Function

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics