Forum Discussion

mcintosb's avatar
mcintosb
Occasional Contributor
6 years ago
Solved

Script Extenson: All Parameters are Undefined

I'm creating my first script extension and I'm running into a serious wall with the Parameters object.

 

I have this code: 

function AdvWait_OnCreate(Data, Parameters)
{
  Parameters.URL = "hello.world";
}

function AdvWait_OnExecute(Data, Parameters)
{
  Log.Event(Parameters.URL);
}

I would expect this to result in a log event with the title "hello.world", but the title is blank. If I try to put Parameters.URL in the Additional Info section of the log, it prints as "undefined". The code otherwise seems to work, but it's no use if I can't access or use my parameters.

 

If it helps, this is my description file:

<ScriptExtensionGroup>
    <Category Name="Keyword Test Operations">
        <ScriptExtension Name="Advanced Wait" Version="0.1">
          <Description>Pauses the script for a set time until the page loads.</Description>
            <Script Name="AdvWait.js">    <!-- Specify the script file name here -->
                <KDTOperation Name="Advanced Wait" Category="Test Actions">
                    <Parameters>
                        <Parameter Name="URL"/>
                    </Parameters>
                    <Columns>
                        <Column Name="Item" Value="Advanced Wait" />
                        <Column Name="Value" Editable="True" EditorType="Parameters" />
                    </Columns>
                    <Events>
                        <Event Name="OnCreate" Routine="AdvWait_OnCreate" />
                        <Event Name="OnExecute" Routine="AdvWait_OnExecute" />
                    </Events>
                </KDTOperation>
            </Script>
        </ScriptExtension>
    </Category>
</ScriptExtensionGroup>

Both have been cut down significantly, but this problem persists whether I have one parameter or a dozen. Any help would be appreciated.

  • tristaanogre's avatar
    tristaanogre
    6 years ago

    OK!  I got it!

    So... in your OnExecute event handler, you need to change the code to the following.

    function AdvWait_OnExecute(Data, URL)
    {
      Log.Event(URL);
    }

    As per the help, for this handler, you don't pass in the Parameters object, you pass in the actual parameters themselves in the order in which they are defined in the Description.xml file (see https://support.smartbear.com/testcomplete/docs/working-with/extending/script/creating/keyword-test-operations/events/onexecute.html)

     

    So... you probably don't need the custom form as discussed earlier... just change this code.

     

    Also... you're doing a Log.Event.  So, you need to make sure that under Tools -> Current Project Properties -> Playback you have the "Store last ___ events" set to 0.  Events are suppressed unless an error or warning is logged in which case it will write out the number of events set in that value.  If it's set to 0, all events get logged.

11 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I think default parameter values only apply if you actually have a custom user defined form, otherwise it just uses the basics from the default wizard.  Do you have a User Form defined and included in your extension?

    • mcintosb's avatar
      mcintosb
      Occasional Contributor

      Ah, right. I don't have a user form.

       

      However, in testcomplete, when I create or edit an instance of this operation (with this OnSetup method I forgot to include the first time) ...

       

      function AdvWait_OnSetup(Data, Parameters)
      {
        return true;
      }
      <Event Name="OnSetup" Routine="AdvWait_OnSetup" />

       

      ... the operation parameters screen opens and I can see that they've been set by the OnCreate function (see attachment). Is this not representative of the real data in the operation?

      • mcintosb's avatar
        mcintosb
        Occasional Contributor

        I've created a user form and the requisite code for setting Parameter values, but that hasn't changed anything.

         

         

        function AdvWait_OnSetup(Data, Parameters)
        {
          var frm = UserForms.AdvWaitForm;
          frm.textURL.Text = Parameters.URL;
          
          // Display the Operation Properties dialog and check the results
          if (frm.ShowModal() != mrOk) {
            return false;    // No changes were made
          }
          
          Parameters.URL = frm.textURL.Text;
          return true;
        }

        With that code, I can set the form data and see the new url in the operation perameters screen, or change it in the operation perameters screen and see the change in the form data next time it opens.

         

        But this code: 

        function AdvWait_OnExecute(Data, Parameters)
        {
          Log.Event(Parameters.URL);
        }

        ... still produces a log with a blank title, or the text "undefined" if printed in additional info. I don't understand the problem here.