cancel
Showing results for 
Search instead for 
Did you mean: 

Script Extenson: All Parameters are Undefined

SOLVED
Occasional Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Script Extenson: All Parameters are Undefined

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-...)

 

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
11 REPLIES 11
Community Hero

Re: Script Extenson: All Parameters are Undefined

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?


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Script Extenson: All Parameters are Undefined

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?

Occasional Contributor

Re: Script Extenson: All Parameters are Undefined

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

 

2019-02-08_8-50-02.png

 

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.

Community Hero

Re: Script Extenson: All Parameters are Undefined

Can you upload your extension that you are working with?  I'd like to play with this and see if I can figure out what's up.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Script Extenson: All Parameters are Undefined

Sure, thanks. I'm currently using version 12.31 by the way. If this ends up being a problem that's solved in later versions, I can push my company for an upgrade.

Community Hero

Re: Script Extenson: All Parameters are Undefined

Do you have one that functions?  This one is missing the icon file for the operation.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Script Extenson: All Parameters are Undefined

It functions just fine for me, but sure, here's one with an icon.

Community Hero

Re: Script Extenson: All Parameters are Undefined

OK... with that, when I drag the operation over, I first get prompted to enter the URL.  Whatever I type in there, gets input into the operation and the test runs. 

Is this not the behavior you're seeing?


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Script Extenson: All Parameters are Undefined

The operation runs, but it's supposed to create a log entry with the input URL (Parameters.URL, as in the OnExecute function) as its title. Whenever I try this, the title is blank. If the URL is printed out in the "additional info" section of the log, it prints as "undefined" no matter what the URL actually is. I can't seem to perform any operations on any parameters, even integers and booleans, because they're somehow undefined despite the data clearly existing within the program.

Top Kudoed Authors