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.

Requirement:-
Launching and running UFT script from VAPI-XP in ALM

Implementation:-

Step1:- 
Create a simple Test in UFT with following lines of code.


Msgbox “Hello World!!”,,“My First VAPI-XP in UFT”

Step2:-
Write the following lines of code in our local txt file.
Hint:- It invokes UFT and execute the “Hello World!!” code

Hello World Test in UFT
Hello World!!

Code:-

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

Step3:-
Run the VAPI-XP in Test Lab and we are done.

Happy Learning!!Please feel free to share your feedback and comments.

Leave a Reply

Your email address will not be published. Required fields are marked *