TruClient 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.
Create a function
You can define functions to add to a library.
To create a function:
-
Select the Functions libraries view from the View list at the top of the Development window.
-
Select an existing library from the library list, or click the New library button to create a new library.
-
Click the New Function button to create a new function. Enter a name for the new function.
-
Click More to open the Step editor.
-
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.
-
Close the Step editor.
-
Drag or paste steps into the new function.
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.
Create a function within a script
- Highlight the steps in the script to include in the function. To select multiple steps, press CTRL.
- Right-click the highlighted steps and select Group Into > New Function which opens the Create New Function dialog box.
-
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.
Create a global library
-
From the views list at the top of the Development window, select Functions libraries.
-
Select an existing library from the library list.
-
Click the Export button to export the library to a location on your file directory as an .xml file.
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.
Use a function in a script
-
Click Add step in the menu toolbar.
-
In the Functions tab, drag and drop Call function to the correct location in your script.
-
Expand the step and select a library and a function.
-
(Optional) Click More and specify the argument values in the Arguments section. For details, see Create a function within a script.
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 |
|
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.
See also: