Storing Script Extension Options Between TestComplete Sessions

Applies to TestComplete 15.47, last modified on January 20, 2023

To customize script extensions, you can specify a set of script extension options.

Options are declared in description files with the Option elements as child elements of the Script elements. Each script can have a set of various options distinct by their names specified by the Name attribute.

XML


<Script Name="Sample_Script.vbs">
  …
  <Option Name="Sample_Option" />
  …
</Script>

Script extension options can be obtained and changed from the script extension source code. To obtain an option from script, use the Options run-time object and specify the name of the needed option.

JScript

// Displays TestOption’s value in the message box.
aqDlg.ShowMessage(Options.TestOptions);

VBScript

' Displays TestOption’s value in the message box.
aqDlg.ShowMessage Options.TestOption

Options can be obtained only from those scripts which they are declared for in the description file. You cannot access options specified for other scripts or for other script extensions.

Also, you can specify a default value for options. Use the DefaultValue attribute to set the initial option value. If the default value is not specified, the option value is considered an empty string.

XML

<Option Name = "Sample_Option" DefaultValue = "100" />

Options can specify script execution conditions, data or user forms custom settings. Just like persistent project and project suite variables, script extension options store their values between TestComplete sessions, and changes made to them during the current TestComplete session become available during the next session. This allows you to share data between script extension executions.

Note: If a script extension option has been changed, after TestComplete is restarted, it is the new modified value which becomes available, not the initial one. Consider this when creating script extensions and make sure that modifying the option cannot cause the script to fail.

Script extension options are user-specific. Changes made to the options under one account are not available under another account. This allows you to create more flexible script extensions that modify their options according to the current account’s specifics.

Example

The following example shows how to declare an option with the default value in the description file and how to obtain the option from the script extension source code:

Description XML file

<ScriptExtensionGroup Name = "Test Extensions">
  <Category Name = "Tests">
    <ScriptExtension Name = "Sample Extension" Author = "SmartBear Software" Version = "1.0 test" HomePage = "smartbear.com">
      <Script Name = "SampleScript.js">
        <Option Name = "TestOption" DefaultValue = "1.0.0" />
        <DesignTimeAction Name = "Test" Icon = "TestIcon.bmp" Routine = "Test"/>
      </Script>
      <Description>Sample script extension.</Description>
    </ScriptExtension>
  </Category>
</ScriptExtensionGroup>

JScript

function Test()
{
  UserForms.TestForm.ShowModal();
  Options.TestOption = UserForms.TestForm.teInput.Text;
}

function TestForm_OnShow(Sender)
{
  UserForms.TestForm.teInput.Text = Options.TestOption;
}

VBScript

Sub Test
  UserForms.TestForm.ShowModal()
  Options.TestOption = UserForms.TestForm.teInput.Text
End Sub

Sub TestForm_OnShow(Sender)
  UserForms.TestForm.teInput.Text = Options.TestOption
End Sub

Note that the example uses a user form with the text edit element to display and obtain the option value. For more information on using User Forms in script extensions, see Using Forms in Script Extensions. For other information on creating custom design-time actions, see the Creating Actions Tutorial.

See Also

Script Extensions
Creating Script Extensions
Options Object (Script Extensions)
Option Element
Structure of the Description File

Highlight search results