Highlighted
liorde Honored Contributor.
Honored Contributor.
594 views

Invoke UFT from VBScript with parameters

Hello colleagues.
I ahve not been able to find something that provides  a good slution for this issue. I need to invoke a UFT script via command line so I choose to do this by VBS. 3 parameters should be sent from the VBScript to the UFT.
I have written something from a collection of examples I found online but it simply doesnt do the job. Either I have an unreferenced object or parameters are sent empty.

In the relvant test I created a link between the test parameters and the action parameters. (Is this necessary)? 

Please give your thoughts here. Cant get this code to work right...


Here is the VBS code:

' =================================================
'=================================================

Dim qtApp, arrTests(2), i
Dim blnNeedChangeAddins, arrTestAddins
'Dim sDomain, sProject, sUser, sPass


' The array of tests to be launched.
' ----------------------------------
arrTests(0) = "D:\SharePoint\Login_and_Download_XLS" '' download of the CSV file

Set qtApp = CreateObject("QuickTest.Application")

'Go through all tests in the set
' ------------------------------
arr_cnt = ubound (arrTests)
For i = 0 to arr_cnt

For j = 1 to 1

If (arrTests(i) = "") Then
Exit For
End If

'Check neccessary Add-ins are ACTIVE !
' ------------------------------------
arrTestAddins = qtApp.GetAssociatedAddinsForTest(arrTests(i))
blnNeedChangeAddins = False
For Each testAddin In arrTestAddins
''' msgbox "Addin associated is : " & testAddin '***********************
addin_status = ""
addin_status = qtApp.Addins(testAddin).Status
''' msgbox "Addin status is : " & addin_status '***********************
If addin_status <> "Active" Then
blnNeedChangeAddins = True
Exit For
End If
Next

' If a change is necessary, exit QuickTest to modify the loaded add-ins
' ---------------------------------------------------------------------
launch_status = qtApp.Launched
If launch_status And blnNeedChangeAddins Then
qtApp.Quit
End If

' Load the add-ins
' ----------------
If blnNeedChangeAddins Then
Dim blnActivateOK
blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription)
If Not blnActivateOK Then
MsgBox errorDescription
WScript.Quit
End If
End If

''' msgbox "blnNeedChangeAddins is : " & blnNeedChangeAddins
If (blnNeedChangeAddins = True) then
msgbox "Need to change the Add-Ins", 0, "AddIns required!"
msgbox "Required AddIns are : Web , .Net .", 16, "AddIns required!"
Exit For
End If

' If QuickTest is not yet open
' ----------------------------
If Not qtApp.Launched Then
qtApp.Launch
End If

' launch UFT in it's visible mode.

' Set the Test Parameters
Set pDefColl = qtApp.Test.ParameterDefinitions
Set qtpParams = pDefColl.GetParameters()

'Set the value for test environment through command line
On Error Resume Next
'qtpParams.Item("env").Value = LCase(WScript.Arguments.Item(0))
qtpParams.Item("TestParam1").Value = "environment"
'qtpParams.Item("browser").Value = LCase(WScript.Arguments.Item(1))
qtpParams.Item("TestParam2").Value = "browser"
On Error GoTo 0

for each elem in qtpParams
msgbox elem
next

''Run QTP test
'QTP.Test.Run qtpResultsOpt, FALSE, qtpParams
qtApp.Visible = True
qtApp.Open arrTests(i), true '' launching the script !!
qtResults.ResultsLocation = qtApp.Test.Environment("TestDir")&"\Res1"
qtApp.Test.Run qtResults, true, qtpParams

Next

' If load sequence need a change in the add-ins
If (blnNeedChangeAddins = True) then
msgbox "Need to change the Add-Ins", 0, "AddIns required!"
Exit For
End If

Next

qtApp.Quit

0 Likes
7 Replies
liorde Honored Contributor.
Honored Contributor.

Re: Invoke UFT from VBScript with parameters

One of the errors I recieve is this, for this line of code:

 

vbs_launch_err.JPGqtApp.Test.Run qtpResultsOpt, true, qtpParamsqtApp.Test.Run qtpResultsOpt, true, qtpParams

 

 

 

0 Likes
RajkumarR Outstanding Contributor.
Outstanding Contributor.

Re: Invoke UFT from VBScript with parameters


@liorde wrote:

 

 

' Set the Test Parameters
Set pDefColl = qtApp.Test.ParameterDefinitions
Set qtpParams = pDefColl.GetParameters()

'Set the value for test environment through command line
On Error Resume Next
'qtpParams.Item("env").Value = LCase(WScript.Arguments.Item(0))
qtpParams.Item("TestParam1").Value = "environment"
'qtpParams.Item("browser").Value = LCase(WScript.Arguments.Item(1))
qtpParams.Item("TestParam2").Value = "browser"
On Error GoTo 0


Can you check if you have these two parameters defined in your UFT test?

_____________________
Rajkumar Rajangam
0 Likes
RajkumarR Outstanding Contributor.
Outstanding Contributor.

Re: Invoke UFT from VBScript with parameters


@liorde wrote:

In the relvant test I created a link between the test parameters and the action parameters. (Is this necessary)? 

 


You could do it this way or use the TestArgs("ParamName") to get the paramter value from the action & avoid parameter mapping.

_____________________
Rajkumar Rajangam
0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: Invoke UFT from VBScript with parameters

Hi Rajkumar .


These 2 parameters are indeed defined in that specific script.
But the error that showed in not very clear to me. What is the problem there?

Thank-you.

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: Invoke UFT from VBScript with parameters

You are correct, there is actually no need to use the parameter linkage option. I fixed it in my script.

Still, how do I solve that critical error that shows upon launching if the UFT?

 

0 Likes
RajkumarR Outstanding Contributor.
Outstanding Contributor.

Re: Invoke UFT from VBScript with parameters

I have found the error in your AOM script.

You are setting the Parameter values before you open the Test. But the error is suppressed and propogated due to the use of On Error resume Next statement.


@liorde wrote:

On Error Resume Next
'qtpParams.Item("env").Value = LCase(WScript.Arguments.Item(0))
qtpParams.Item("TestParam1").Value = "environment"
'qtpParams.Item("browser").Value = LCase(WScript.Arguments.Item(1))
qtpParams.Item("TestParam2").Value = "browser"
On Error GoTo 0 


So Open the Test & then set the Params.

qtApp.Open arrTests(i), true '' launching the script !!

' Set the Test Parameters
Set pDefColl = qtApp.Test.ParameterDefinitions

_____________________
Rajkumar Rajangam
0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: Invoke UFT from VBScript with parameters

Hello  Rajkumar.

Thank-you for the advice. This works now. 
Had to open the script the set the parameters when running it.


0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.