Back to Blog

Enhancing a TruClient Script – Part 3

Introduction to TruClient – Part 1
Recording in TruClient – Part 2
Working with Objects, Variables, and Code in TruClient – Part 4 

Parameters

Define your parameters just like you normally would for an HTTP script.
There are several ways you can use parameters in a script.  The easiest way is to change the argument section of the step is to use the parameter from Plain to JavaScript.

Select the text you want to parameterize and right click it.  From the menu, you can create a new parameter or select from an existing one.


This will add the TC.getParam function with the corresponding parameter name.

You can also manually use the TC.getParam function.   For example, you can assign it to a variable in order to use it multiple times.  You do this by dragging Evaluate Java Script from the Toolbox under Miscellaneous to a section of the script before you need to use it.  In the Arguments sections add this:

var po = TC.getParam(“c_po”);

po is now available in all argument sections in your script.

You can also use just TC.getParam(“c_po”); in any value location if you don’t want to assign a variable to the parameter.

NOTE: In 12.53 you can now use the name of the parameter directly in argument locations if you change the argument type to parameter.

Additionally, if the variable is contained in Javascript that is executed (e.g., “Javascript” identification with evalXPath), the parameter is available via ArgsContext.LR.GetParam(“c_po”) or ArgsContext.c_po.

Correlation and Verification

Yes, the whole idea is that TruClient gets rid of correlation, but you still need to grab dynamic data from the application and use it some other place.  A good example of this is a PO number.  There are at least two ways to do correlation.

1. Using Verify Function

  1. Drag the Verify Function to the script when the value is visible
  2. Select the object you want to capture
  3. Under Arguments select the property “Visible Text”
  4. For Variable add the name of the variable “ponumber” with the double quotes!
  5. At this point ponumber is a usable variable.  If you have problems with scope you may want to assign it to Global, Global.ponumber=ponumber.  Please see the scope section below for more details.  You can also assign it to a LR parameter, LR.setParam(“c_ponumber”, ponumber);  This is helpful if you need to pass it to a C function.

2. Using Evaluate JS on Object

  1. Drag the Evaluate JS on Object to the script where the value is visible
  2. Select the object you want to capture
  3. Under Arguments for Code add ponumber=object.value; or if you want it globally available, Global.ponumber=object.value.

When you want to use the value, you can usually just use the name without quotes, ponumber or Global.ponumber.

Dealing with Think Time

As you may have noticed there isn’t a think time function.  Instead there is a wait function.  You can use it just like think time.  There are two approaches you can take.

Run-Time Settings:
In Run-Time Settings under Replay, there is a section called Minimum Time.  You can use these settings to control what the wait function will do.  You can setup a random percentage or use a minimum time.

Variables:
Additionally, if you want more control over your wait time you can use a variable.   Set this variable at the start of the script.

Generic global think time:

tt = 10;

Pass the think time via an additional argument:

var tt;
 tt = TC.getAttr("a_tt");
 if (tt.length==0)
 {
   tt = 10;
 }

Use random think times from 5 to 15 seconds:

tt = Math.floor(11*Math.random()+5);

Next Up:
Working with Objects, Variables, and Code in TruClient – Part 4 

Back to Blog