TruClient Functions and Function Libraries

This section describes how to create TruClient functions and a function library, which enable you to use the functions locally, or share them for use in other scripts.

Functions overview

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.

Note: Libraries replace the older method of keeping custom code in JS-functions.js (this file is still supported for backward compatibility).

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: Global libraries are not supported in TruClient Lite.

Back to top

Create a function library and function from the TruClient Development Window

  1. Select the Functions Libraries tab at the bottom of the TruClient Development Window.

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

  3. Click the button to create a new function. This inserts a new unspecified function.

  4. Click the button to expand the function.

  5. Define the step including function name and end event.

  6. Define the function arguments using the Argument Editor. Argument names should be meaningful so that when you are using the function it is clear what value you need to specify.

  7. Define the transaction using the Transaction Editor. For details, see Insert Transactions.

Back to top

Use a reference to a function argument within the function.

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

For example:

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

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. Select the Functions Libraries tab at the bottom of the TruClient Development Window.

  2. Select an existing library from the list.

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

Back to top

Copying 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 the script

  1. Click the TruClient Toolbox.
  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. Specify the arguments' values in the augments section. For details, see Create a function within a script . (Optional)
  6. Specify transactions in the transaction section. (Optional) For details, see Insert Transactions.

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 Export 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: