Forum Discussion

dpirs's avatar
dpirs
Occasional Contributor
14 years ago

Access Keyword test parameters from my own keyword test operation

I have created my own keyword test operation (script extension). How can I access the keyword test parameters (not keyword test operation parameters) and variables in the script extension code?



Thanks,



Daniel

4 Replies

  • Hi Daniel,



    Script extension code has access only to the keyword test operation parameters, but not to test parameters and test variables. So, you can read values of the test parameters and variables only if the user has specified them as the operation parameters.
  • dpirs's avatar
    dpirs
    Occasional Contributor
    Thanks,



    so, how can user specify the test parameter as the operation parameter? I can have an edit box in my form that is used for configuration of my keyword operation where user can enter the test parameter name, whose value should be used as a operation parameter, but how can I get the test parameter value from the code?



    I don't know if it is clear. I have one operation parameter, let us say 'UpperLimit'. In the configuraion dialog user can enter the value for the parameter (some number like '5') or enter the name of the test parameter whose value should be used for the 'UpperLimit'. During execution, I have to get the value of the test parameter somehow.

    Another example - built in operation 'Compare Properties' has operational parameter 'Value'. Using configuration dialog, user can select the Mode for operation parameter: it can be a 'Constant' or 'Test Parameter'. If user selects the 'Test Parameter' he can select which test parameter is used for 'Value' operational parameter. So if I do the same, I have to access the value of selected 'Test Parameter' in my code during the execution to get its value.



    Regards,



    Daniel  
  • Hi Daniel,



    Thanks for the clarification, now I have a clearer picture of what you mean.



    The "Operation Parameters" dialog (like the one used in the Compare Properties operation) is actually common to all keyword test operations, including those created using script extensions. To use this built-in dialog for your custom operation, you need to define the operation parameters in the description.xml file and specify the Parameters editor for the Value column:



    <KDTOperation Name="..." Category="..." Icon="...">

      <Parameters>

        <Parameter Name="MyParam"/>

          ...

      </Parameters>

      ...

      <Columns>

        <Column Name="Value" Editable="True" EditorType="Parameters"/>

        ...

      </Columns>

    </KDTOperation>


    In this case, when the user adds the operation to the test or clicks the ellipsis button in the Parameters column, TestComplete will pop up the standard Operation Parameters dialog where the user can select test parameters or variables among other values.



    In the script extension code, you can access the run-time values of the operation parameters (whether they are hard-coded or specified using test parameters or variables) via Parameters.ParamName. For more infromation, please see the Implementing Parameters Editor section of the Implementing In-Place Editing Support article.





    If you wish, you can also create a custom configuration form for your operation in addition to using the standard Operation Parameters dialog. (See Creating the Operation Setup Routine.) You might want to do this to make use of special edit components, such as TcxCheckBox for boolean values, TcxSpinEdit for numbers, TcxComboBox for option lists, and so on.



    Your custom configuration form will be displayed before the Operation Parameters dialog. However, while users can enter parameter values using check boxes, combo boxes and other controls you've added, they won't be able to select test parameters or variables here, because you can't access them from script extensions. It's considered an "advanced" feature that is only available in the Operation Parameters dialog shown after your custom form. So, if users want to select a test parameter or variable, they can close your custom form and proceed to the Operation Parameters dialog.





    And the last thing. What if the user previously selected a test variable or parameter for the operation and then invokes the configuration dialog? Since you can't display test parameters and variables in your custom edit form, you need to skip it and display the standard Operation Parameters dialog instead. To do this, your OnSetup event handler should first call aqObject.GetVarType to check the stored parameter types - in case of test parameters or variables, it's varEmpty. So, if one or more stored parameter types are varEmpty, you need to skip the code.



    Since script extensions can't directly access test parameters and variables, you can't display them in custom edit forms. However, what if the user previously selected them in the standard Operation Parameters dialog? In this case, your OnSetup event handler should first call aqObject.GetVarType to check the stored parameter types - in case of test parameters or variables it will be varEmpty. If so, you need to skip the code related to your custom configuration form. Check out the first example in the Creating the Operation Setup Routine article for an example of how to do this.



    Hope this helps!
  • dpirs's avatar
    dpirs
    Occasional Contributor
    Thanks, this was very helpful!



    I have done one small operation and now I finally understand how this works. I will try to implement it in my code now.



    Daniel