TruClient 2.0 functions and function libraries

This topic describes how to create TruClient functions. It also describes how to create a function library which enables you to use the functions locally, or share them for use in other scripts.

About functions

A function is a reusable group of steps you define to perform a task. You store functions in libraries that can contain more than one function.

A library can be local or global:

  • A local library can be accessed by the script that created it.

  • A global library can be shared locally or on the network, and accessed by all TruClient scripts that can access the share location.

    Note:  

    • Recursive calls to functions are not allowed.

    • Global libraries are not included in the automatic backup and recovery process.

Back to top

Create a function

You can define functions to add to a library.

To create a function:

  1. Select the Functions libraries view from the View list at the top of the TruClient Development window.

  2. Select an existing library from the library list, or click the New library button to create a new library.

  3. Click the New Function button to create a new function. Enter a name for the new function.

  4. Click More to open the Step Editor.

  5. Define the function arguments. Give the arguments meaningful names so that when you are using the function, it is clear what value you need to specify.

  6. Close the Step Editor.

  7. Drag or paste steps into the new function.

Back to top

Reference a function argument within the function

To access the function arguments within the function, use the syntax FuncArgs.<arg_name>.

For example:

Note: This is only relevant when using the JavaScript editor.

Back to top

Create a function within a script

  1. Highlight the steps in the script to include in the function. To select multiple steps, press CTRL.
  2. Right-click the highlighted steps and select Group Into > New Function which opens the Create New Function dialog box.
  3. To assign steps that contain arguments, expand the argument section, and insert the function FuncArgs.<argument name>.

    Tip: To insert JavaScript as the argument value, click the button to access the JavaScript editor.

Back to top

Create a global library

  1. From the views list at the top of the TruClient Development window, select Functions libraries.

  2. Select an existing library from the library list.

  3. Click the Export button to export the library to a location on your file directory as an xml file.

Back to top

Copy a test object between object repositories

The local object repository contains the object definitions for a script and the script's local library. A global object repository contains the object definitions for one global library. There are as many independent global object repositories as there are global libraries. If you copy and paste a step that contains a test object within one object repository, the new step is linked to the test object of the step you copied.

However, if you copy steps containing test objects between object repositories, you create new, independent test objects that point to the same UI element. These copies are not linked to each other. To keep these objects pointing to the same UI element:

  • If you change or update one of the test objects in the local library or the script, you must update that object in the global library or libraries.
  • If you change or update one of the test objects in a global library, you must update that object in the script or local library and in any other global library that contains the same object.

Examples of pasting between object repositories that create new test objects are:

  • Copying from a script or local library to a global library.
  • Copying from a global library to a script or local library.
  • Copying between global libraries.

If you copy more than one step between object repositories, you create as many copies of the test object as there were in the steps you pasted. This applies even if you copy more than one step in a single paste operation.

Back to top

Use a function in a script

  1. Click Add step in the menu toolbar.

  2. In the Functions tab, drag and drop Call function to the correct location in your script.

  3. Click the Call Function link to expand the function.

  4. Specify the library and the function in the step section.

  5. (Optional) Specify the arguments' values in the augments section. For details, see Create a function within a script.

  6. (Optional) Specify transactions in the transaction section. For details, see Insert transactions in TruClient 2.0 scripts.

Back to top

Create New Function dialog box

This dialog box enables you to create new functions and assign functions to a library.

To create a new function, right-click the highlighted steps, and select Group into > New function.

UI Element Description
Function name Enables you to specify a function name.
Add to library
  • Select existing. Saves new function to an existing library.

  • Create new. Saves new function to a new library.

Replace steps with function call If selected, TruClient automatically inserts a call function in place of steps.

Note:  

  • When working with a global library, you can save changes to the library by clicking the Save Global Library button.

  • If you save the library to a network location, other users can click the Import Library button to import the library.

  • Click the Delete Library button to remove the library from the script. Global libraries are not deleted by this action.

  • Click the Refresh function call arguments button to update the arguments when a function is modified; this also indicates if there is an issue with the arguments.

Back to top

See also: