Launching UFT with VAPI-XP from ALM? – User friendly Tech help
Let us further enhance our code to launch UFT script from VAPI-XP in ALM. We are already familiar with “Hello World!!” code in VAPI-XP .We are going to run the same line of code but this time we are utilizing UFT to execute it.
n
nRequirement:-
nLaunching and running UFT script from VAPI-XP in ALM
n
nImplementation:-
n
Step1:-
nCreate a simple Test in UFT with following lines of code.
n
Msgbox “Hello World!!”,,“My First VAPI-XP in UFT”
n
Step2:-
nWrite the following lines of code in our local txt file.
nHint:- It invokes UFT and execute the “Hello World!!” code
n
n
Hello World!! |
n
Code:-
n
Sub Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun)
On error resume next
'Taking the UserName
Set objNW = CreateObject("Wscript.Network") sUserName = objNW.UserName
Set objNW = Nothing
'Creating the UFT object
Set objUFT = CreateObject("QuickTest.Application")
Do While Err.Number 0 Err.Clear Sleep 2000
Set objUFT = CreateObject("QuickTest.Application")
Loop
'Launch uft if not launched
If Not objUFT.Launched Then objUFT.Launch
'Make UFT visible
If objUFT.Visible = False Then objUFT.Visible = True
'Incase UFT is already running stop the excution
If objUFT.Test.IsRunning Then objUFT.Test.Stop
'Open the Test
objUFT.Open "C:Users" & sUserName & "Test"
'Run the Test objUFT.Test.Run
'Destroying the Object
Set objUFT = Nothing
End Sub
n
Step3:-
nRun the VAPI-XP in Test Lab and we are done.
n
nHappy Learning!!Please feel free to share your feedback and comments.