8. Creating the Design-Time Action's Code

Applies to TestComplete 15.63, last modified on April 10, 2024

After having created the form, we can now create a design-time action. The creation of this action is similar to the creation of the record-time action:

  • Create the script code that will be executed when a user selects an item from the Tools toolbar.

  • Add information about the action to the description.xml file.

As you remember, the design-time action should generate the checkpoint code and display it in the Copy Text to Clipboard dialog. The code snippet below performs these tasks. Open the clcCode.js unit for editing and add this code to it:

JScript

[clcCode.js]

// Design-time action
function DesignTimeExecute()
{
  var syntax;

  // Generate comparison code
  syntax = CreateSyntax();
  if (syntax == null)
    return;

  // Create the Copy Text to Clipboard form
  var ctcForm;
  ctcForm = UserForms.ctcForm;
  ctcForm.ResetForm();

  // Display the comparison code in the form
  ctcForm.cmScriptText.Lines.Text = Syntax.GenerateSource(syntax);

  // Show the form on the screen
  ctcForm.ShowModal();
}

The DesignTimeExecute function will be executed when a user selects our action from the Tools toolbar. Let’s explore the function’s code.

First, we call the helper CreateSyntax routine to generate the checkpoint code. We wrote code for the CreateSyntax function on one of the previous steps.

Then, we obtain a reference to the user form we created and call its ResetForm method to initialize the form’s controls. The user form is not deleted when it is closed. So, the next time a user calls the action and the form will be shown on screen, the form’s components will contain the data that the user specified during the previous call. The ResetForm method helps us re-initialize the form:

JScript

[clcCode.js]

...
// Design-time action
function DesignTimeExecute()
{
  var syntax;

  ...
  var ctcForm;
  ctcForm = UserForms.ctcForm;
  ctcForm.ResetForm();
  ...

After we re-initialized the form, we generate the script code and display it in the form:

JScript

[clcCode.js]

// Design-time action
function DesignTimeExecute()
{
  ...
  var ctcForm;
  ctcForm = UserForms.ctcForm;
  ctcForm.ResetForm();

  // Display the comparison code in the form
  ctcForm.cmScriptText.Lines.Text = Syntax.GenerateSource(syntax);

  ...
}

Finally, we show the form on screen:

JScript

[clcCode.js]

// Design-time action
function DesignTimeExecute()
{
  ...
  // Show the form on screen
  ctcForm.ShowModal();
}

After the form is shown, the user can use it as their needs dictate. They can modify the generated code, copy it to clipboard or close the form without performing any actions.

Prev     Next

See Also

Creating Custom Actions
Creating Actions - Basic Concepts
Writing Action Code
Using Forms in Script Extensions

Highlight search results