Convert TruClient actions to code

TruClient provides a hybrid solution that enables users to create both non-coded and coded actions. This enables you to take advantage of fast script development available with TruClient when you create a script. You can then convert selected actions to code, making it easier to add complex logic and customized functions to the script.


  • This feature is provided as a tech preview version, and is available in TruClient Standalone and TruClient in VuGen.

  • This feature is supported in TruClient Web scripts only.

Workflow: Convert TruClient actions to code

This section describes the end-to-end workflow for converting a TruClient action to code.

Step 1: Convert a TruClient action to code

Step 2: Replay and enhance the converted script

Step 3: Debug the coded script

Back to top

Benefits of converting TruClient actions to code

Benefits of converting actions to code include:

  • Ability to create complex scripts. Converting TruClient actions to code makes it easier to add complex logic to your script. Although TruClient has a rich set of built-in functions, in some cases it is necessary to implement custom functions. For example, if you want to programmatically change the object description. After converting a TruClient action to code, you can customize the action and add complex logic to improve your load testing abilities.

  • Faster processing. While TruClient provides you with the ability to quickly and easily record complex business processes, the more complex an application's client logic is, the more resources are required to process the script during replay. When a script has a large number of steps, the user interface can get busy and this can affect TruClient performance. When you convert actions to code, the script is saved as a text file—thus accelerating script processing.

Back to top

Step 1: Convert a TruClient action to code

  1. Open a TruClient script.

    You can use an existing script, record a new TruClient script, or start from an empty action. If you use an empty script, skip to step 3.

  2. Replay the script (optional).

    We recommend replaying the script and correcting any errors that occur during the process.

    Note: If you convert the script to code without first replaying the script, steps will not have automatic end events.

  3. Configure the script conversion settings.

    1. Click the Convert to Code button to open the TruClient Coded Conversion Settings dialog box.

    2. Select the scope of the script to convert:

      • Current action. Converts only the currently selected action to code.
      • All non-coded actions. Converts all non-coded actions in the script to code.
    3. Select the object identification method:

      • TruClient managed object repository. TruClient continues to manage the object repository after conversion (this option supports all object identification methods). This is the default option.

      • User managed object repository. Enables you to create objects and manage the object repository.

        If you selected this option, configure the following conversion settings:

        UI Element Description
        Select default identification method

        Select the object identification method to use: XPath (default), JavaScript, or Descriptors.

        Note: The Automatic object identification method is not supported.

        Keep predefined identification for non-Automatic methods If selected, retains all predefined identification methods, except for Automatic, which is replaced by the default identification method selected above. Clear this option to replace all predefined identification methods with the default identification method.
        Include other object identification method as comments If selected, includes the other object identifiers as comments in the code.

        Include objects roles as a comment

        If selected, includes all object roles as a comment in the code.
    4. Configure the step conversion options.

      • Add a comment before each step. Adds a comment describing each step to the code.

      • Include all step arguments (Optional Step). Includes step arguments with their default values in the code.

        Note: Choosing this option results in a significantly longer coded script.

      • Include conversion warnings. Includes warning comments as a result of converting actions to code. This can include warnings for changing the end event in a transaction, or for using a different step.

    5. Click Convert to convert the selected action, or all non-coded actions, to code.

      Actions that have been converted to code are indicated as such in the action box .

      After conversion, objects created by TruClient are shown as:

      TCS.object.tcManaged.<object name>.operation(arguments)

      User created objects are shown as:


    Note: You can roll back the conversion at any time by clicking . When you undo the conversion, you lose all changes made to the code, and return to the original model of the action in the script.

Back to top

Step 2: Replay and enhance the converted script

You can insert JavaScript code into preexisting steps in the arguments fields of most steps. This allows you to perform multiple customizations to enhance you load testing abilities.

  1. Replay the script (optional).

    We recommend replaying the script and correcting any errors before inserting code.

    1. Select the down arrow next to the replay button , and select Replay step by step to view the replay more slowly and in a controlled manner. Repeat this procedure after each step to continue the step by step replay.

      You can view script action details in the status area.

      Note: When replaying a coded script step by step, TruClient only pauses on steps that begin with TCS.

      In the example below, the replay pauses only on the navigate and click functions, and not on the x variable definition and increasing it by 1.

      	"Location": TCS.argType.JSArg("\"\"")
      var x = 1;
      x = x+ 1;{
      	"X Coordinate": 108,
      	"Y Coordinate": 8
    2. Identify the End Event for each step (optional).

      If you converted the script without replaying it first, no end events are defined in the step arguments. To add end events manually, enter the end event argument in the format:

      "End Event": TCS.argType.endEvent.<select end event>

      For the list of end events, see TCS.endEvent.<end event type>.

      You can also change end events that were automatically generated or selected before converting the script, by selecting a different event.


      • If you replayed the script before conversion, TruClient sets an automatic end event only for the browser being recorded. After conversion, this end event is used by default for all browsers.
      • If you manually changed an end event before conversion, TruClient automatically generates an end event for all the browsers.
  1. Enhance the coded script.

    Tip: Click Detach Coded Window to open the code editor in a separate expanded window, making it easier to edit code and work with two screens.

    You can insert JavaScript code into preexisting steps in the converted script, or create new coded steps using TruClient coded functions. This enables you to perform multiple customizations.

    To add additional objects to the script, click , and select:

    • Add TruClient managed object. Enables you to add additional TruClient managed objects to the script. To do so, select a new object in the application browser window. The object details are displayed in the Create Object window. After you select an object, you can use it by name.

      After pasting the managed object, you can modify the coded name, name, and selected identification method.

    • Generate object code. Enables you to add additional user-defined objects to the script.

      To generate code for a new object, select the object in the application browser window. TruClient provides you with the code options to copy into the script in the Object Details window.

      Edit the object code as required, and then click to copy the code, and paste it into the script. For the list of TruClient coded objects, see Object.

Back to top

Step 3: Debug the coded script

The following table lists the actions available to debug the coded script.

Action How to
Run step by step Use the Replay step by step option (available from the Replay button dropdown menu) to aid debugging of the code. Replay is stopped at each line that starts with a TCS. statement.
Use event handlers

Click to add event handlers to help your test recover smoothly. For details, see Event handlers.

Update objects

To make changes to an object, right-click an object, and select Update Object.

You can change the coded name, name, and identification method for the object.

You can also click to regenerate the code for the selected object.

Make a step optional To make a step optional, add the argument "Optional Step": true to the step.
Insert breakpoints

To insert a toggle breakpoint, right-click the relevant step, and select Toggle Breakpoint.

Note: Breakpoints only work in Interactive mode, and they only stop on TruClient APIs—not on custom logic.

Use Inspector Panel

Use the Inspector Panel, displayed at the bottom of the TruClient Development window, to do a detailed inspection of variable values in the code at a specific point in your script. The panel is displayed automatically during replay when it is triggered by one of the following:

  • A TCS.utils.breakpoint() line
  • Toggle breakpoint
  • Using step by step replay

The panel displays user-defined variables in the code. You can add an expression defined in the code, and view detailed information for that expression, including adding and removing variables.

  • The first time the Inspector Panel is displayed, there is no expression set. After an expression is added, it is saved for each time the panel is displayed.
  • If you add a variable to the code, it is defined at the next breakpoint.
  • The Inspector Panel does not show parameters. However, you can add a parameter, as follows:

    1. Add the line var paramVal = TCS.parameters.get("NewParam1");
    2. Add paramVal to the Inspector Panel.

For more details on using the Inspector Panel, see Insert toggle breakpoints.

Note: The variables defined in the Evaluate JavaScript code step are not supported.

Insert a wait step

Use the TCS.utils.wait function to insert a wait step. This delays the next step from starting for the specified time.

Identify objects

Use the highlighter to check if an object is visible in the application at any time.

  • For TruClient managed objects, right-click the object name (a line starting with TCS.object.tcManaged), and select Highlight.

  • For user managed objects, right-click the coded object (a line starting with "JavaScript", "XPath", or "Descriptors"), and select Highlight.

Generate snapshots

Use the TCS.utils.snapshot function to generate a snapshot during replay.

Edit general settings

Click to open the TruClient General Settings, and modify the settings that apply to the script. For details, see Configure TruClient general settings.

Display log messages

Click to display log messages in the User Output window while debugging the script (in the lower left side of the Development window). This window shows TCS.log messages.


Check for syntax errors

Click to check for exceptions in the code.

Back to top

Notes and limitations

  • The Automatic identification method is not supported for user managed object repositories.

  • Functional Libraries cannot be converted to code (however, they can be used from a coded action).

  • Related objects in a script, and transactions with a non-default End Event cannot be converted to code.

  • Action on error in the Interactive Options tab of General Settings is not supported.

  • Any change to the End Event in a grouped step is ignored when a script action is converted to coded.

  • If you are using ECMAScript 6, you will be able to run the script on IE, but it will fail to verify the code.

Back to top

See also: