Synchronous functions
The below synchronous functions can be used in every field in TruClient that can evaluate JavaScript, such as in step arguments, objects, and descriptor fields. However, while synchronous functions can be used in objects and descriptor fields, this use is not recommended because it can cause unexpected results.
Note:
-
Support for using synchronous APIs in JavaScript code will be deprecated in a future version. OpenText recommends using asynchronous APIs instead. For details, see Replace synchronous APIs with asynchronous APIs.
-
TruClient - Native Mobile scripts do not support asynchronous APIs. OpenText recommends using Generic API Action steps instead. For details, see Replace synchronous APIs with Generic API Action steps.
-
TruClient 2.0 - Web scripts support asynchronous functions only. For details on supported functions, see Using asynchronous functions with TruClient 2.0 - Web scripts.
General notes on using TruClient functions
-
Use escape backslashes in path arguments. For example,
c:\\temp\\myFile.ps1
.
-
The following arguments can be used with any method:
-
object. The step's object as defined in the application.
-
AUT.window. Points to the global window object within the active window or tab of the application.
-
AUT.document. The global document object within the active window or tab of the application.
The AUT API provides a common mechanism for handing the AUT window and AUT document for all TruClient protocols. For details, see Use JavaScript in the AUT window.
-
Vuser functions
Adds a filter for URL requests.
Note: Relevant only for steps that have a network-related end event, or that do not have any end event.
Arguments
filters. Filter representing one or more URLs (string). Separate multiple URLs with a semicolon (;). The URL can have the wildcard (*) which can match 0 or more characters.
include. True to include URL requests that match the filter; otherwise false (default). Optional argument (boolean).
applyTo. (Optional argument) Specify the type of request the filter applies to:
-
Xhr. Filters XHR requests only.
-
NonXhr. Filters non-XHR requests only.
-
All. Filters all requests (default).
Note: You cannot use exclude and include filters at the same time.
Return value (void)
undefined
Example:
TC.addNetworkFilter("http://www.myco.com/*", true, "All")
From the point that you add this API call, until you call the remove filter or the end of the iteration, TruClient does not wait for requests to get a response unless the URL has a http://www.myco.com/
prefix.
Removes all URL request filters.
Note: Relevant only for steps that have a network-related end event, or that do not have any end event.
Arguments
None
Return value (void)
undefined
Example
None
Starts logging URL requests.
Note: Relevant only for steps that have a Step completed or Step synchronous network completed end event, or that do not have any end event.
Arguments
None
Return value (void)
undefined
Example
None
Stops logging URL requests.
Note: Relevant only for steps that have a Step completed or Step synchronous network completed end event, or that do not have any end event.
Arguments
None
Return value (void)
undefined
Example
None
Advances the specified parameter to the next value in the file. This must be a parameter of type file or unique number; this is the argument type set in VuGen.
Arguments
name. The name of the parameter to advance (string).
Return value (void)
undefined
Example
TC.advanceParam("multi_row_param");
Returns the IP address when IP spoofing is enabled and the script is running in load mode in Controller.
Arguments
None
Return value (string)
Returns the IP address when IP spoofing is enabled and the script is running in load mode in Controller.
Example
None
Saves a string to a parameter, creating a temporary parameter value in the memory if it does not exist (it does not create a parameter that can be read in the next run).
Arguments
name. The name of the parameter in which to save the value (string).
value. The parameter value (string).
Note: Only alphanumeric and the underscore character ("_") are supported.
Return value (void)
undefined
Example
TC.setParam("myparam", "paramVal");
Begins a transaction in a Vuser script that will be ended in another Vuser script.
Arguments
name. The name of the transaction (string).
identifier. The identifier of the transaction (string). The same value is used by TC.crossTransactionEnd(name, identifier, type) to identify the transaction.
Return value (void)
undefined
Example
None
Same as TC.log at the Standard log level with the additional ability to show the message in the Controller's Output window as a notification.
Arguments
text. The message text (string).
Return value (void)
undefined
Example
TC.outputMessage("My output message");
Ends a transaction in a Vuser script that has been started in another Vuser script.
Arguments
name. The name of the transaction (string).
identifier. The identifier of the transaction (string). The value of the parameter must be identical to the value of the identifier param that the Vuser initiating the transaction used in TC.crossTransactionStart(name, identifier).
type. One of the following: "Pass", "Fail", "Auto", "Abort", or "Stop".
Return value (void)
undefined
Example
None
Returns the duration of a specific transaction, in seconds.
Note: This API must be used within the scope of the transaction.
Arguments
name. The name of the transaction (string).
Return value (string)
Returns the duration of a specific transaction, in seconds.
Example
None
Returns the value of the specified parameter.
Arguments
name. The parameter name (string).
Return value (string)
Returns the value of the specified parameter. If the parameter does not exist, it returns an empty string.
Example
Note: You can also use the VuGen toolbar to manage parameters in the script. For details, see Use parameters to vary arguments.
Runs a specific function in C language, defined in the C-functions.c file.
Note: Support for this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
funcname. The function name (string).
#include
command to include the file where the function is defined.functimeout. The maximum expected runtime, in seconds, of the function called by the step (number). The default timeout is 60 seconds.
Return value (void)
undefined
Example
TC.evalC("myFunc", 20);
Logs a message as a line in Virtual User Generator’s interactive/load log.
Arguments
text. The message (string).
level. Optional argument. One of the following:
- "Error"
- "Warning"
- "Standard" (default)
- "Extended"
- "Status" - sends a string to the Status area of the Controller. It also sends the string to the Vuser log. When run from VuGen, the message is sent to output.txt.
- "Status_msg"
Return value (void)
undefined
Example
TC.log("my warning", "Warning");
Returns the text after unmasking.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
text. The masked text (string).
Return value (string)
Returns the text after unmasking.
Example
TC.unmask(str);
Records a user-defined data point for analysis.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
name. The name of the data point (string). Do not begin a data-point name with any of these strings: HTTP, NON_HTTP, RETRY, mic_, stream_, mms_
value. The numeric value (number).
Return value (void)
undefined
Example
TC.userDataPoint("myDP", 1);
Returns an array of the objects defined by the XPath in the argument.
Arguments
xpath. The xpath query (string).
Return value (void)
undefined
Example
evalXPath("//a[text()=\" Books \"]");
Starts a LoadRunner transaction.
Arguments
name. (String) The name of the transaction to start.
Return value (void)
undefined
Example
TC.startTransaction("login_tr1");
Ends a LoadRunner transaction.
Arguments
name. The name of the transaction to end (string).
status. One of the following values: “Pass”, “Fail”, “Auto”
If the value passed to status is "Auto", then the actual value of status is automatically assigned. By default, this value is "Pass", signifying a successful transaction. However, if prior to TC.endTransaction, you change the default value by using TC.setTransactionStatus(status) or TC.setTransactionStatusByName(status, name), or the system detects an error on script execution (in this case, the system sets all open transactions status to "Fail"), then this is the value which is passed as status in TC.endTransaction.
Return value (void)
undefined
Example
TC.endTransaction("login_tr1", "Auto");
Sets the default end status of open transactions.
Arguments
status. One of the following transaction status values: "Pass", "Fail". The "Auto" status is not applicable.
The TC.setTransactionStatus function sets the default end status of currently open transactions which have "Auto" in their TC.endTransaction(name, status) statement.
If you make a series of calls to functions that modify the "Auto" status, then it is the last call before TC.endTransaction that effectively changes the status.
Return value (void)
undefined
Example
TC.setTransactionStatus("Fail")
Sets the default end status of a single open transaction by the transaction name.
Arguments
status. One of the following transaction status values: "Pass", "Fail". The "Auto" status is not applicable.
name. The name of the transaction to set.
The TC.setTransactionStatusByName function sets the default end status of the transaction with the defined name. This transaction must have "Auto" in its TC.endTransaction(name, status) statement.
If you make a series of calls to functions that modify the "Auto" status, then it is the last call before TC.endTransaction that effectively changes the status.
Return value (void)
undefined
Example
TC.setTransactionStatusByName("Fail", "T1")
Indicates which Vuser is handling a specific script.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
text. Any text string (string).
Return value (void)
Undefined.
Example
TC.vuserStatusMessage("FlightStatus");
Enables you to change the log level during script replay. To restore initial log level setting, use TC.restoreLogLevel.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
level. Specify the log level:
- "Disabled". Disables the log level. It still captures a log including the error level.
- "Standard". Standard log captured.
- "Extended". Extended log file captured.
log_flags. (Object) If the log level is set to extended, you can specify which data is captured using Boolean(true/false) flags as properties of json_object.
Any flag which is omitted is considered as “false”.
- log_http
- log_AUT
- log_parameters
Return value (void)
undefined
Example
-
Disable the log level:
TC.setLogLevel(“Set the log level to “Disabled”);
-
Enable the standard log:
TC.setLogLevel(“Standard”);
-
Enable the extended log:
TC.setLogLevel(“Extended”);
-
Enable the extended log, and specify which logs to capture:
TC.setLogLevel(“Extended”,{ log_http : true, log_AUT: true, log_parameters: true});
Restore log level to the initial setting.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
None
Return value (void)
undefined
Example
TC.restoreLogLevel();
Browser functions
Enables you to set a proxy address manually in the script.
Arguments
option. Specify the type of proxy you want to use:
- "PROXY_NONE". No proxy.
- "PROXY_SYSTEM". Use system proxy; settingsString is ignored.
- "PROXY_MANUAL". Manually set proxy.
- "PROXY_PAC". Use a proxy auto-config (PAC) file.
settings. The details of the proxy setting (string).
Return value (void)
undefined
Example
-
Use system proxy settings. The second argument is ignored, so it can be any string value, usually empty.
Note: Because schema needs two arguments, the second one cannot be omitted.
TC.setProxy("PROXY_SYSTEM", "")
; -
Manually set proxy and set separate proxy for different protocols (http & https)
TC.setProxy("PROXY_MANUAL", '{"proxyShare":false,"proxyHttp":" proxy.xxx.com ","proxyHttpPort":8080,"proxySsl":" proxy.yyy.com ","proxySslPort":8080}');
-
Manually set proxy and share the proxy settings for all protocols (http, https, …)
Note: If you also specify an address for “proxySsl”, it is ignored because “proxyShare” is set to true.
TC.setProxy("PROXY_MANUAL", '{"proxyShare":true,"proxyHttp":"proxy.xxx.com","proxyHttpPort":8080}');
-
Use manually set proxy which is already in memory (maybe set previously, maybe nothing is set).
Note: If you are not sure which setting is in memory, it is recommended that you explicitly specify the proxy settings you want to use every time.
TC.setProxy("PROXY_MANUAL ", "");
-
Do not use any proxy.
Note: The proxy address/port that are set in the options sections are not removed. The settings in memory can be activated in another call (refer to the next example).
TC.setProxy("PROXY_NONE", "");
-
Use PAC.
TC.setProxy("PROXY_PAC",'{"proxyPAC":"http://autocache.xyzcorp.net/"}')
Adding a filter to one of the denylist or allowlist lists of URLs. The URL of each HTTP request is checked first against the denylist, and then the allowlist. HTTP requests that do not pass the check are blocked.
Arguments
url. String or regular expression representing the URL (string).
isIncluded. True to add the URL to allowlist, or false to add the URL to denylist (boolean).
Return value (void)
undefined
Example
Set only the allowed domain on the allowlist. All other domains are blocked.
String example:
Utils.addAutoFilter("http://www.myco.com/*", true);
Regular expression example:
Utils.addAutoFilter(/^http:\/\/www\.myco\.com\/.*/, true);
Remove all filters from both the denylist and allowlist lists of URLs.
Arguments
None
Return value (void)
undefined
Example
Utils.cleanupAutoFilters();
Adding an HTTP header to every consecutive HTTP requests following this function call.
Arguments
header. The name of the header to be added (string).
value. The value of the header to be added (string).
merge. "True" indicates to merge the value with an existing header by the same name; "false" indicates to overwrite it (boolean).
Note: Merge does not support modifying the following headers: "content-type", "content-disposition", "content-length", "user-agent", "referer", "host", "authorization", "proxy-authorization", "if-modified-since", "if-unmodified-since", "from", "location", "max-forwards"
Return value (void)
undefined
Example
Utils.addAutoHeader("someCustomHeader", "someValue", true);
Removes all HTTP headers and stops adding HTTP headers to every consecutive HTTP request following this function call.
Arguments
None
Return value (void)
undefined
Example
Utils.cleanupAutoHeaders();
Removes an HTTP header added with Utils.addAutoHeader
and stops adding this HTTP header to every consecutive HTTP request following this function call.
Arguments
header. The name of the header to be stopped from being added.
Return value (void)
undefined
Example
Utils.removeAutoHeader("someCustomHeader");
Remove a filter that was added using Utils.addAutoFilter
from the denylist or allowlist of URLs.
Arguments
filter. String representing the URL.
isInclude. True value indicates the allowlist, false otherwise.
Remarks
Use the exact same filter URL value that was added to the list.
Return value (void)
undefined
Example
Utils.removeAutoFilter("http://www.myco.com/*", true);
Removes all cookies currently stored by the Vuser.
Arguments
None
Return value (void)
undefined
Example
None
Clears the cache of a single Vuser; the content of the whole cache simulator is unaffected.
Arguments
None
Return value (void)
undefined
Example
None
VTS functions
Adds a new cell as the last field of a column to a value.
Equivalent method in LoadRunner: lrvtc_send_message
Arguments
colName. The name of the column (string).
value. The value as a string (string).
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column specified in the argument does not exist, the column is created and the cell content is set to the argument value.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcAddCell("MyColumn","myValue","MyVts");
Sets the data in multiple columns.
Equivalent method in LoadRunner: lrvtc_send_row1
Arguments
colNames. The column names delimited by a semicolon (string).
values. The values as a string delimited by a semicolon (string).
option. Define how the values are added (integer).
- 0. Add as same row in all columns based on the column with the highest row count. The created row is n+1 for all columns.
- 1. Add as stack - last row in every column.
- 2. Add as unique stack - last row in every column only if the value is unique in the column.
vtsName. The alias of the VTS server (string, optional).
Remarks
If the columns specified in the argument do not exist, the columns are created and the cell contents are set to the argument values.
Return value (number)
1 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcAddCells("MyColumn1;MyColumn2;MyColumn3", "MyValue1;MyValue2;MyValue3", 0, "MyVts");
Sets the last field of a column to a value if the value does not exist in the column.
Equivalent method in LoadRunner: lrvtc_send_if_unique
Arguments
colName. The name of the column (string).
value. The value (string).
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column specified in the argument does not exist, the column is created and the cell content is set to the argument value.
Return value (boolean)
True if the value exists in the column, and false if the value does not.
Example
TC.vtcAddUniqueCell("MyColumn",1,"MyVts");
Clears all data in a column.
Equivalent method in LoadRunner: lrvtc_clear_column
Arguments
colName. The name of the column (string).
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column specified in the argument does not exist, the step runs without returning an error and no data in the VTS is changed.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcClearColumn("MyColumn","MyVts");
Clears the data in a field.
Equivalent method in LoadRunner: lrvtc_clear_message
Arguments
colName. The name of the column (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column or the row index specified in the argument does not exist, the step runs without returning an error and no data in the VTS is changed.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcClearCell("MyColumn",1,"MyVts");
Clears the values from all fields in a row.
Equivalent method in LoadRunner: lrvtc_clear_row
Arguments
rowIndex. The index number of the field (integer). 1 is the first field in the column.
VtsName. The alias of the VTS server (string, optional).
Remarks
If the row index specified in the argument does not exist, the step runs without returning an error and no data is changed in the VTS.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcClearRow(1,"MyVts");
Returns the number of fields that contain data in a column.
Equivalent method in LoadRunner: lrvtc_column_size
Arguments
colName. The name of the column (string).
vtsName. The alias of the VTS server (string, optional).
Return value (number)
Returns the number of fields in the column if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcColumnSize("MyColumn","MyVts");
Creates a connection to the server (supports HTTP).
Equivalent method in LoadRunner: lrvtc_connect
Note: To connect using HTTPS, basic or NTLM authentication, use TC.vtcConnectEx.
Arguments
serverName. Either the IP or server name (string).
port. The port number (integer).
vtsName. The alias of the VTS server (string, optional).
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcConnect("MyServer", 8888, "MyVts");
Creates a connection to the server (supports HTTP, HTTPS version VTS server, basic authentication based on user name and password entered by the user, and NTLM authentication).
Equivalent method in LoadRunner: lrvtc_connect_ex
Arguments
serverName. Either the IP or server domain name (string). The protocol can be omitted; the default protocol is “https://”.
port. The port number (integer). The available range is 1-65535.
userName. The user name for basic or NTLM authentication (string, optional).
password. The password for basic or NTLM authentication (string, optional).
domain. The domain name for NTLM authentication (string, optional).
vtsName. The name of the VTS connection (string, optional).
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcConnectEx("MyServer", 8888, "MyUser", "MyPW", "MyDomain", "MyVts");
Creates a column.
Equivalent method in LoadRunner: lrvtc_create_column
Arguments
colName. The name of the column (string).
VtsName. The alias of the VTS server (string, optional).
Remarks
If a column of the same name already exists, the function does nothing.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcCreateColumn("MyColumn","MyVTS")
Disconnects from the server.
Equivalent method in LoadRunner: lrvtc_disconnect
Arguments
vtsName. The alias of the VTS server (string, optional).
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcDisconnect( "MyVts");
Returns the data in a field.
Equivalent method in LoadRunner: lrvtc_query_column
Arguments
colName. The name of the column (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
vtsName. The alias of the VTS server (string, optional).
Return value (string)
String if data exists in the specified column and row. It returns a null if the specified column or index does not exist.
Example
TC.vtcGetCell("MyColumn",1,"MyVts");
Returns the data in a row as a JavaScript object. The properties of the object is set to the column names
Equivalent method in LoadRunner: lrvtc_query_row
Arguments
rowIndex. The index number of the field (integer). 1 is the first field in the column.
vtsName. The alias of the VTS server (string, optional).
Return value (object)
Returns the field from the specified index in all columns. If the column does not have a value in the specified index, it returns an empty string. For example, {col1:"larry",col2:""}
. If the column specified in the argument does not exist, a null value is returned for every column.
Example
TC.vtcGetRowCells(1,"MyVTS");
Increments a counter stored in a field.
Equivalent method in LoadRunner: lrvtc_increment
Arguments
colName. The name of the column (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
value. The value.
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column name specified in the argument does not exist, the column is created and the cell referenced by the index is set to the argument value.
If the index specified in the argument exceeds the column size, the cell is created by the specified index and the cell contents is set to the argument value.
If the column referenced by the index contains a string, the cell contents are replaced with the value argument.
If the column referenced by the index contains an integer, the value will be incremented to the integer.
Return value (number)
0 if completed successfully. If unsuccessful, it throws an exception.
Example
TC.vtcIncrement("MyColumn",1,1,"MyVTS");
Pops the first field from a column.
Equivalent method in LoadRunner: lrvtc_retrieve_message
Arguments
colName. The name of the column (string).
vtsName. The alias of the VTS server (string, optional).
Return value (string)
The value of the first index in the column. Returns null if the column is empty or does not exist.
Example
TC.vtcPopCell("MyColumn","MyVts");
Pops the data in a row as a JavaScript object.
Arguments
vtsName. The alias of the VTS server (string, optional).
Return value (object)
Returns the first field from the columns. If the column is empty, the value is null. Example: {col1:”larry”,col2:null}
Example
TC.vtcPopCells( "MyVts");
Pops the first fields from specified columns. Returned as a JavaScript object. The properties of the object are set to the column names.
Equivalent method in LoadRunner: lrvtc_retrieve_messages1
Arguments
colNames. The names of the columns (string).
vtsName. The alias of the VTS server (string, optional).
Return value (object)
Returns the first field from the specified columns. If the column is empty, the value is null. For example, {col1:"larry",col2:""}
Example
TC.vtcPopMultipleCells("MyColumn","MyVts");
Retrieves the first field from the specified column and moves the values to the bottom.
Equivalent method in LoadRunner: lrvtc_rotate_messages
Arguments
colName. The name of the column (string).
option. Define how the values are rotated (integer).
-
1. Add as stack - Retrieve data from column, and move it to the bottom to the last valid row of every column.
-
2. Add as unique stack - Retrieve data from column, and move it to the bottom to the last valid row if the data is unique.
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column name does not exist, a null value is retrieved and a new column will be added to the table.
Return value (string)
Returns the first field from the specified column. If the column is empty, the value is an empty string.
Example
TC.vtcRotateCell("MyColumn1", 1, "MyVts");
Retrieves the first field from all columns and moves the values to the bottom.
Equivalent method in LoadRunner: lrvtc_rotate_row
Arguments
colName. The name of the column (string).
option.How to rotate the values (integer).
- 0. Same row – Retrieve data from all columns and move it to the bottom for all columns, based on the column with the highest row count. The created row is n+1 for all columns.
- 1. Add as stack - Retrieve data from the column and move it to the bottom to the last valid row of every column.
- 2. Add as unique stack - Retrieve data from the column and move it to the bottom to the last valid row of every column only if the data is unique.
vtsName. The alias of the VTS server (string, optional).
Return value (string)
Returns the first field from the specified column. If the column is empty, the value is an empty string. If the column name does not exist, it retrieves a null value and adds a new column to the table.
Example
TC.vtcRotateCells ("MyColumn", 1, "MyVts");
Retrieves the first field from the specified columns and moves the values to the bottom.
Equivalent method in LoadRunner: lrvtc_rotate_messages1
Arguments
ColNames. The column names delimited by a semicolon (string).
option. Define how the values are rotated (integer).
-
0. Same row – Retrieve data from all columns and move it to the bottom for all columns based on the column with the highest row count. The created row is n+1 for all columns.
-
1. Add as stack - Retrieve data from all columns, and move it to the bottom to the last valid row of every column.
-
2. Add as unique stack - Retrieve data from all columns, and move it to the bottom to the last valid row of every column if the data is unique.
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column name does not exist, it retrieves a null value and adds a new column to the table.
Return value (object)
Returns the first field from the specified columns. If the column is empty, the value is an empty string. Example:
{col1:"larry",col2:""}
Example
TC.vtcRotateMultipleCells("MyColumn1;MyColumn2;MyColumn3", 0, "MyVts");
Searches for a row containing specific values in specific columns.
Equivalent method in LoadRunner: lrvtc_search_row
Arguments
columns. The names of the columns to search. The column names are separated by the delimiter.
values. The values of the columns to search. The values are separated by the delimiter.
delimiter. The character that separates the column names and values in the lists. If a string, rather than a single character, is passed in delimiter, the string as a whole is the delimiter.
VtsName. The alias of the VTS server.
Remarks
If the column specified in the argument does not exist, the return value is empty.
Return value (number)
0: If the API call succeeded, but no row was found.
1: If the API call succeeded and the row was found.
If the API call failed, it returns the error code.
(object)
If the value of columns exists, it returns all row values, for example {col1:"a", col2:"b",col3:"c"}. If the value of columns does not exist, it returns null.
Example
TC.vtcSearchRow("col1,col2","a,b",",","test");
Replaces a specific value inside a set of columns with a new value.
Equivalent method in LoadRunner: lrvtc_update_all_message_ifequals
Arguments
ColNames. The column names delimited by a semicolon (string).
Message. New value (string).
Ifmessage. Original value (string).
Delimiter. Delimiter to separate column names. By default, the separator value is a semicolon (;).
Return value (number)
0 if successful. For a failure, it throws an exception.
Example
TC.vtcUpdateAllMessageIfequals("MyColumn1;MyColumn2;MyColumn3", "NewVal1", "OldVal1");
Replaces the data in a field.
Equivalent method in LoadRunner: lrvtc_update_message
Arguments
colName. The name of the column (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
value. The value (string).
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column name or index does not exist, the column and/or cell referenced by the index are created and the cell contents set to the argument value.
Return value (number)
0 if successful. For a failure, it throws an exception.
Example
TC.vtcUpdateCell("MyColumn",1,"MyValue","MyVTS");
Replaces the data in a field if the current data equals a given value.
Equivalent method in LoadRunner: lrvtc_update_message_ifequals
Arguments
colName. The name of the column (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
value. The replacement value (string).
comparedValue. If the current cell contents are the same as the comparedValue, the cell contents are replaced with value (string).
vtsName. The alias of the VTS server (string, optional).
Return value (boolean)
False if a field with the same value exists; True if there is no field with the same value in the column.
Example
TC.vtcUpdateEqualsCell("MyColumn",1,"MyValue","MyCompareValue","MyVTS");
Replaces the data in multiple fields.
Equivalent method in LoadRunner: lrvtc_update_row1
Arguments
ColNames. The column names delimited by a semicolon (string).
rowIndex. The index number of the field (integer). 1 is the first field in the column.
values. The values as a string delimited by a semicolon (string).
vtsName. The alias of the VTS server (string, optional).
Remarks
If the column name or index does not exist, the column and/or cell referenced by the index are created, and the cell contents set to the argument value.
Return value (number)
0 if successful. For a failure, it throws an exception.
Example
TC.vtcUpdateRowCells("MyColumn1;MyColumn2;MyColumn3", 1, "MyNewValue1;MyNewValue2;MyNewValue3", "MyVts");
Environment functions
Returns the value of the command line parameter passed to the test or its default value. If the attribute doesn't exist, it returns an empty string.
Arguments
name. The name of the command-line parameter (string).
The command-line parameter name is generally assigned by the user in the Additional Attributes tab in VuGen > Runtime Settings or in the Controller in the group command line argument.
When the test is run, the additional attribute or the group command line argument is passed to the test as a parameter in the command line. During test run, the value can be accessed with this function.
Return value (string)
Returns the value of the command line parameter passed to the test or the default value set for it. If the attribute does not exist, it returns an empty string.
Example
To get the Controller command line argument, -MyServerURL http://myserver.com
, call:
TC.getAttr(“MyServerURL”);
Creates the specified folder. If needed, creates all the folders necessary to complete the path.
Arguments
path. The absolute path of the folder (string).
Return value (void)
undefined
Example
IO.createDir(TC.outputDir + "mydir");
Deletes the specified folder or file. If a folder is specified, deletes all the files in the folder, including sub-directories.
Arguments
path. The absolute path of the folder or file (string).
Return value (void)
undefined
Example
IO.delete(TC.outputDir + "mydir")
Determines if the specified folder or file exists.
Arguments
path. The absolute path of the folder or file (string).
Return value (boolean)
True if the path exists; False if it does not.
Example
IO.isExist(TC.outputDir + "mydir")
Returns all the data from the specified file. Converts the data from the specified charset to unicode.
Arguments
filename. The absolute path of the file (string).
charset. The charset of the file, if it is not UTF-8 (string).
Return value (string)
All the data from the specified file.
Example
var log = IO.read(TC.scriptDir + "mylog.txt");
TC.log(log);
Writes the string to the specified file. If the file does not exist it is created.
Arguments
filename. The absolute path to the file (string).
input. The string to write to the file (string).
append. (boolean)
- true. Append the string to the end of the file (default).
- false. Overwrite the file with the string.
charset. The charset of the file, if it is not UTF-8 (string).
Return value (boolean)
Always returns true.
Example
IO.write(TC.scriptDir + "mylog.txt", "first msg\n", false);
IO.write(TC.scriptDir + "mylog.txt", "second msg");
The result content in the mylog.txt file:
first msg
second msg
Returns the value of the specified environment variable. Returns an empty string if the specified variable does not exist.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
name. The name of the environment variable (string).
Return value (string)
Value of the specified environment variable. Returns an empty string if the specified variable does not exist.
Example
var path = Utils.getEnv("PATH");
Evaluates the specified JavaScript file in the arguments context.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
filename. The absolute path to the JavaScript file (string).
Return value (void)
undefined
Example
Utils.import(TC.scriptDir + "myjs.js");
Returns true if the specified environment variable exists and false if it does not exist.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
name. The name of the environment variable (string).
Return value (boolean)
True if the specified environment variable exists, and false if it does not exist.
Example
Utils.isEnvExists("PATH"); // returns true
Utils.isEnvExists("TC_kukuku"); // returns false
Sets the named environment variable to the specified value. If the variable already has a value it is overwritten.
Note: Support for using this API in JavaScript code will be deprecated in TruClient. We recommend using the Evaluate C step instead.
Arguments
name. The name of the environment variable (string).
value. The value to which to set the environment variable (string).
Return value (void)
undefined
Example
Utils.setEnv("PATH", "C:\\loadrunner\\");
See also: