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