Find the Number of Parameters in a Parameter Definitions Collection

Hi ,

I tried below code but unable to retrieve count value of action parameter.

 

'************************************************************************************************************************
'Description:
'
'This example opens a test with predefined parameters,
' gets a collection of parameter definitions, Loops on it and display each parameter details,
' gets a collection of run-time parameters, change the value of one of them, run the test with parameters,
' after the test run - display the value of one of the out parameters.
'
'Assumptions:
' the test D:\Tests\Mytest contain in parameter called "InParam1" and out parameter called "OutParam1"
'************************************************************************************************************************

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim pDefColl 'As QuickTest.ParameterDefinitions ' Declare a Parameter Definitions collection
Dim pDef ' As QuickTest.ParameterDefinition ' Declare a ParameterDefinition object
Dim rtParams 'As QuickTest.Parameters ' Declare a Parameters collection
Dim rtParam ' As QuickTest.Parameter ' Declare a Parameter object
'Dim cnt, Indx As Integer

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start UFT
qtApp.Visible = True ' Make the UFT application visible

qtApp.Open "C:\Users\durgesh.c.kumar\Desktop\UFT_AOM_Scripts\ParamTest"

' Retrieve the parameters collection defined for the test.
Set pDefColl = qtApp.Test.ParameterDefinitions

MsgBox "Before the count statement"
'cnt = pDefColl.Count
cnt = 2
MsgBox cnt ' showing zero always
Indx = 1

' Display the names and values of each of the parameters in the collection.
While Indx <= cnt
Set pDef = pDefColl.Item(Indx)
MsgBox "Param name: " & pDef.Name & "; Type: " & pDef.Type & "; InOut: " & pDef.InOut & "; Description: " _
& pDef.Description & "Default value: " & pDef.DefaultValue
Indx = Indx 1
Wend

Parents
  • Do you get the expected parameter values when you hardcode cnt?

  • No @rFish_911  
     i executed with hardcode cnt value but it threw an error message. 

  • Are your parameters set at the test level or at the action level? Your script, and the below script, will display test level parameters, but not action level parameters. I suspect your parms are set at the action level which is why your cnt = 0.

    Option Explicit
    
    Dim app, parms, parm, i
    
    Set app = CreateObject("Quicktest.Application")
    app.Launch
    app.Visible = True
    
    app.Open "C:\Users\durgesh.c.kumar\Desktop\UFT_AOM_Scripts\ParamTest"
    
    Set parms = app.Test.ParameterDefinitions
    
    MsgBox parms.Count
    
    For i = 1 to parms.Count
       Set parm = parms.Item(i)
       MsgBox "(" & i & ") parm.Name: """ & parm.Name & """" & Chr(13) & _
          "parm.Description: """ & parm.Description & """"
       Set parm = Nothing
    Next
    
    app.Test.Close
    
    Set app = Nothing
  • Q. Are your parameters set at the test level or at the action level?

    Ans: Action level.

    @rFish_911 is there any way to display action level parameters?

     

  • Q. Are your parameters set at the test level or at the action level?

    Ans: Action level.

    @rFish_911 is there any way to display action level parameters?

     

  • Verified Answer

    Indeed there is.

    On a side note, the Automation Object Model Reference is here:
    C:\Program Files (x86)\HP\Unified Functional Testing\help\AutomationObjectModel.chm
    Open the reference and search for "action object members" and for "ActionParameterDefinitions Collection Members" for additional details.

    Try this for action parameters:

    Option Explicit
    
    Dim app, actions, parms, parm, i, j
    
    Set app = CreateObject("Quicktest.Application")
    app.Launch
    app.Visible = True
    
    app.Open "C:\Users\durgesh.c.kumar\Desktop\UFT_AOM_Scripts\ParamTest"
    
    Set actions = app.Test.Actions
    
    MsgBox "The test has " & actions.Count & " associated actions."
    
    For i = 1 to actions.Count
       If actions(i).ActionParameterDefinitions.Count > 0 Then
          For j = 1 to actions(i).ActionParameterDefinitions.Count
             MsgBox "actions(" & i & ").Name: """ & actions(i).Name & """" & Chr(13) & _
                "actions(" & i & ").Type: """ & actions(i).Type & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Name: """ & actions(i).ActionParameterDefinitions(j).Name & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Type: """ & actions(i).ActionParameterDefinitions(j).Type & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").InOut: """ & actions(i).ActionParameterDefinitions(j).InOut & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Description: """ & actions(i).ActionParameterDefinitions(j).Description & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").DefaultValue: """ & actions(i).ActionParameterDefinitions(j).DefaultValue & """"
          Next
       Else
          MsgBox "actions(" & i & ").Name: """ & actions(i).Name & """" & Chr(13) & _
             "actions(" & i & ").Type: """ & actions(i).Type & """" & Chr(13) & _
             "has 0 parameters."
       End If
    Next
    
    Set actions = Nothing
    
    app.Test.Close
    app.Quit
    
    Set app = Nothing
Reply
  • Verified Answer

    Indeed there is.

    On a side note, the Automation Object Model Reference is here:
    C:\Program Files (x86)\HP\Unified Functional Testing\help\AutomationObjectModel.chm
    Open the reference and search for "action object members" and for "ActionParameterDefinitions Collection Members" for additional details.

    Try this for action parameters:

    Option Explicit
    
    Dim app, actions, parms, parm, i, j
    
    Set app = CreateObject("Quicktest.Application")
    app.Launch
    app.Visible = True
    
    app.Open "C:\Users\durgesh.c.kumar\Desktop\UFT_AOM_Scripts\ParamTest"
    
    Set actions = app.Test.Actions
    
    MsgBox "The test has " & actions.Count & " associated actions."
    
    For i = 1 to actions.Count
       If actions(i).ActionParameterDefinitions.Count > 0 Then
          For j = 1 to actions(i).ActionParameterDefinitions.Count
             MsgBox "actions(" & i & ").Name: """ & actions(i).Name & """" & Chr(13) & _
                "actions(" & i & ").Type: """ & actions(i).Type & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Name: """ & actions(i).ActionParameterDefinitions(j).Name & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Type: """ & actions(i).ActionParameterDefinitions(j).Type & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").InOut: """ & actions(i).ActionParameterDefinitions(j).InOut & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").Description: """ & actions(i).ActionParameterDefinitions(j).Description & """" & Chr(13) & _
                "actions(" & i & ").ActionParameterDefinitions(" & j & ").DefaultValue: """ & actions(i).ActionParameterDefinitions(j).DefaultValue & """"
          Next
       Else
          MsgBox "actions(" & i & ").Name: """ & actions(i).Name & """" & Chr(13) & _
             "actions(" & i & ").Type: """ & actions(i).Type & """" & Chr(13) & _
             "has 0 parameters."
       End If
    Next
    
    Set actions = Nothing
    
    app.Test.Close
    app.Quit
    
    Set app = Nothing
Children