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.

Note:  

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

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

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.

    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:

      TCS.object.userManaged.*.operation(arguments)

    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

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

      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.

      TCS.browser.navigate({
      	"Location": TCS.argType.JSArg("\"http://16.44.49.218/\"")
        });
      var x = 1;
      x = x+ 1;
      TCS.object.tcManaged.allkindofCGIsObject.click({
      	"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.

      Note:  

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

  2. Debug the coded script.

    Action How to
    Check for syntax errors

    Click to check for exceptions in the code.

    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.

     

    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.

    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.

    Insert breakpoints

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

    You can set breakpoint at lines starting with TCS.<xxx>.

    Note:

    • Setting a breakpoint is not supported in the called JavaScript file when replaying a script in a coded action.

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

    • You cannot see the value of a variable when debugging a coded script. Use TCS.log messages to see the variable value.

    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.

    Make a step optional To make a step optional, add the argument "Optional Step": true to the step.
    Use event handlers

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

    Edit general settings

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

    Generate snapshots

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

    Replay in multiple windows

    Click to open the Replay Window, which shows you which window to use to look for an object when replaying a script that has multiple active windows.

    This is only relevant if you want to highlight or update an object.

    Note: Available in Firefox and Chromium browsers only.

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.

Back to top

See also: