You are on page 1of 8

LR Functions With Examples | Loadrunner Functions With

lr_abort:
Stops the script execution.
lr_advance_param:
It will take the next value in the parameter list.
lr_continue_on_error:
Continue on error even if the request is failed.
lr_convert_string_encoding;
Converts a string to a UTF 8 or Unicode.
lr_db_dataset_action:
Validates database contents by setting checkpoints.
lr_db_connect
Connects to a database.
lr_db_dataset_action
Performs an action on a dataset.
lr_db_disconnect
Disconnects from a database.
lr_db_execute
SQLStatementSubmits an SQL statement to a database.
lr_checkpoint
Validates the value of a parameter against an expected value (checkpoint).
lr_db_get
ValueRetrieves a value from a dataset.
lr_debug_message
Sends a debug message to the LoadRunner output or Application Management agent log file.
lr_decrypt
Decrypts an encoded string.
lr_disable_ip_spoofing
Disables IP Spoofing.
lr_enable_ip_spoofing
Enables IP Spoofing.
lr_end_sub_transaction
Marks the end of a sub-transaction.
lr_end_transaction
Marks the end of a LoadRunner transaction.
lr_end_transaction_instance
Marks the end of a transaction instance.
lr_end_timer
Marks the end of a sub-transaction.
lr_error_message
Sends an error message to theLoadRunner output or Application Management agent log file..
lr_eval_string
Replaces a parameter with its current value.
lr_eval_string_ext
Creates a buffer and assigns it the input string after evaluating embedded parameters.
lr_eval_string_ext_free
Frees the buffer allocated by lr_eval_string_ext.
lr_exit
Exits from the script, action, or iteration.
lr_fail_trans_with_error
Sets the status of open transactions to LR_FAIL and sends an error message.
lr_get_attrib_double
Returns the value of a double type command line parameter.
lr_get_attrib_long
Returns the value of a long integer type command line parameter.
lr_get_attrib_string
Returns a command line parameter string.
lr_get_debug_message
Returns the current message logging settings.
lr_get_host_name
Returns the name of the host executing the script.
lr_get_master_host_name
Returns the name of the machine running the LoadRunner Controller.
lr_get_transaction_duration
Gets the duration of a transaction by its name.
lr_get_transaction_status
Gets the current status of a transaction.
lr_get_trans_instance_duration
Returns the duration of a transaction by its name.
lr_get_trans_instance_status
Returns the current status of a transaction instance.
lr_get_trans_instance_think_time
Gets the think time of a transaction instance specified by its handle.
lr_get_trans_instance_wasted_time
Gets the wasted time of a transaction instance by its handle.
lr_get_transaction_think_time
Gets the think time of a transaction by its name.
lr_get_transaction_wasted_time
Gets the wasted time of a LaoadRunner transaction by its name.
lr_get_vuser_ip
Returns the IP address of the current Vuser. Not applicable for products that do not run Vusers.
lr_load_dll
Loads an external DLL.
lr_log_message
Sends a message to the Vuser log file.
lr_message
Sends a message to the output and log file.
lr_output_message
Sends a message to the output and log file with location information.
lr_next_row
Advances to the next row in the parameter data file.
lr_param_increment
Increments the value of a numerical parameter
lr_param_sprintf
Writes formatted output to a parameter.
lr_param_unique
Generates a unique string and assigns it to a parameter.
lr_paramarr_idx
Returns the value of the parameter at a specified location in a parameter array.
lr_paramarr_len
Returns the number of elements in a parameter array.
lr_paramarr_random
Returns the value of the parameter at a random location in a parameter array
lr_peek_events
Checks for events.
lr_rendezvous
Creates a rendezvous point in the Vuser script.
lr_rendezvous_ex
Sets a rendezvous point in a Vuser script.
lr_resume_transaction
Resumes the collection of transaction data.
lr_resume_transaction_instance
Resumes collecting transaction instance data.
lr_save_datetime
Saves the date and time into a parameter.
lr_save_int
Saves an integer to a parameter.
lr_save_searched_string
Searches for an occurrence of a string in a buffer and saves a portion of the buffer after that string to a parameter
lr_save_string
Saves a null-terminated string as a parameter.
lr_save_var
Saves a variable length string as a parameter.
lr_set_debug_message
Sets a message class for output messages.
lr_set_transaction
Create a transaction manually.
lr_set_transaction_instance_status
Sets the status of a transaction instance.
lr_set_transaction_instance_status
Sets the status of a transaction instance.
lr_set_transaction_status
Sets the status of open transactions.
lr_set_transaction_status_by_name
Sets the status of a transaction by its name.
lr_start_transaction
Marks the start of a transaction and measures the response time of a transaction
lr_start_transaction_instance
Marks the beginning of a transaction instance
lr_start_sub_transaction
Marks the beginning of a sub-transaction.
lr_stop_transaction
Halts the collection of transaction data.
lr_stop_transaction_instance
Stops collecting data for a transaction instance specified by its handle.
lr_think_time
Pauses execution between commands in a script.
lr_user_data_point
Records a user-defined data sample.
lr_user_data_point_ex
Records a user-defined data sample.
lr_user_data_point_instance
Records a user-defined data sample and correlates it to a transaction instance.
lr_user_data_point_instance_ex
Records a user-defined
data sample and correlates it to a transaction instance.
lr_vuser_status_message
Sends a message to the Vuser status area in the Controller.
lr_wasted_time
Removes wasted time from all open transactions.
lr_whoami
Returns information about a Vuser executing the scrip

LR Function With Description

1. When will use web_url function?

The web_url function is an action function that loads the Web page (GET request)
specified by the URL argument. The web_url function does not require a context.

Web_url is recorded only when VuGen is in either URL–based recording mode or in


HTML–based recording mode with the A script containing explicit URLs only option
checked (see VuGen's Recording Options).

2. when will use web_global_verification function ?

The web_global_verification function registers a request to search for the specified text
string in Web pages return by all subsequent Action functions. The script fails if the
Fail condition occurs in any subsequent action function. This is in contrast to the
web_reg_find function which only registers a request for the next Action function.

The web_global_verification function is useful in detecting application level errors that


are not represented by HTTP status codes. To locate errors that are represented by
HTTP status codes, use web_get_int_property.

3. When will use web_set_max_html_param_len function?

The web_set_max_html_param_len function is a Service function that is used when


correlating HTML statements. It is recorded only when correlation during recording is
enabled (see VuGen's Recording Options).

The web_set_max_html_param_len function sets the maximum length of any HTML


string which VuGen can retrieve and save in a parameter. The default value for the
maximum length of a parameter that can be captured during correlation is 256
characters (see web_reg_save_param). To retrieve a string longer than 256
characters, use web_set_max_html_param_len to increase the maximum valid length.
An attempt to save a string whose length exceeds the maximum length will fail.

This function is supported for all Web scripts, and for WAP scripts running in HTTP
mode or Wireless Session Protocol (WSP) replay mode.

4. When will use web_reg_save_param function?

Web_reg_save_param is a registration type function. It registers a request to find and


save a text string within the server response. The operation is performed only after
executing the next action function, such as web_url.

Web_reg_save_param is only recorded when correlation during recording is enabled


(see VuGen's Recording Options). VuGen must be in either URL–based recording
mode, or in HTML–based recording mode with the A script containing explicit URLs
only option checked (see VuGen's Recording Options).

This function registers a request to retrieve dynamic information from the downloaded
page, and save it to a parameter. For correlation, enclose the parameter in braces
(e.g., "{param1}") in ensuing function calls which use the dynamic data. The request
registered by web_reg_save_param looks for the characters between (but not
including) the specified boundaries and saves the information that begins at the byte
after the left boundary and ends at the byte before the right boundary.

If you expect leading and trailing spaces around the string and you do not want them in
the parameter, add a space at the end of the left boundary, and at the beginning of the
right boundary. For example, if the Web page contains the string, "Where and when do
you want to travel?", the call:

web_reg_save_param ("When_Txt", "LB=Where and ", "RB= do", LAST);

With a space after "and" and before "do", will result in "when" as the value of
When_Txt. However,

web_reg_save_param ("When_Txt", "LB=Where and", "RB=do", LAST);

Without the spaces, will result in a value of “when ".

Embedded boundary characters are not supported. Web_reg_save_param results in a


simple search for the next occurrence after the most recent left boundary. For example,
if you have defined the left boundary as the character `{` and the right boundary as the
character `}', then with the following buffer c is saved: {a{b{c}

The left and right boundaries have been located. Since embedded boundaries are not
supported, the `}' is matched to the most recent `{` appearing just before the c.

The ORD attribute is 1. There is only one matching instance.


The web_reg_save_param function also supports array type parameters. When you
specify ORD=All, all the occurrences of the match are saved in an array. Each element
of the array is represented by the ParamName_index. In the following example, the
parameter name is A:

web_reg_save_param("A", "LB/ic=<a href=", "RB=\'>", "Ord=All", LAST);

The first match is saved as A_1, the second match is saved as A_2, and so forth. You
can retrieve the total number of matches by using the following term:

ParamName_count. For example, to retrieve the total number of matches saved to the
parameter array, use:

TotalNumberOfMatches=atoi(lr_eval_string("{A_count}"));

The following table indicates how to use the boundary parameters to save portions of
the parameter string:

This function is supported for all Web scripts, and for WAP scripts running in HTTP or
Wireless Session Protocol (WSP) replay mode.

List of Attributes

Convert: The possible values are:

HTML_TO_URL: convert HTML–encoded data to a URL–encoded data format

HTML_TO_TEXT: convert HTML–encoded data to plain text format

This attribute is optional.

Ignore Redirections: If "Ignore Redirections=Yes" is specified and the server


response is redirection information (HTTP status code 300-303, 307), the response is
not searched. Instead, after receiving a redirection response, the GET request is sent
to the redirected location and the search is performed on the response from that
location.

This attribute is optional. The default is "IgnoreRedirections=No".

LB: The left boundary of the parameter or the dynamic data. If you do not specify an
LB value, it uses all of the characters from the beginning of the data as a boundary.
Boundary parameters are case–sensitive and do not support regular expressions. To
further customize the search text, use one or more text flags. This attribute is required.
See the Boundary Arguments section.

NOTFOUND: The handling option when a boundary is not found and an empty string is
generated.

"Notfound=error", the default value, causes an error to be raised when a boundary is


not found.
"Notfound=warning" ("Notfound=empty" in earlier versions), does not issue an error. If
the boundary is not found, it sets the parameter count to 0, and continues executing the
script.

The "warning" option is ideal if you want to see if the string was found, but you do not
want the script to fail.

Note: If Continue on Error is enabled for the script, then even when NOTFOUND is set
to "error", the script continues when the boundary is not found, but an error message is
written to the Extended log file.

This attribute is optional.

ORD: Indicates the ordinal position or instance of the match. The default instance is 1.
If you specify "All," it saves the parameter values in an array. This attribute is optional.

Note: The use of Instance instead of ORD is supported for backward compatibility, but
deprecated.

RB: The right boundary of the parameter or the dynamic data. If you do not specify an
RB value, it uses all of the characters until the end of the data as a boundary.

Boundary parameters are case–sensitive and do not support regular expressions. To


further customize the search text, use one or more text flags. This attribute is required.
See the Boundary Arguments section.

RelFrameID: The hierarchy level of the HTML page relative to the requested URL. The
possible values are ALL or a number. Click RelFrameID Attribute for a detailed

description. This attribute is optional.

Note: RelFrameID is not supported in GUI level scripts.

SaveLen: The length of a sub–string of the found value, from the specified offset, to
save to the parameter. This attribute is optional. The default is –1, indicating to save to
the end of the string.

SaveOffset: The offset of a sub–string of the found value, to save to the parameter.
The offset value must be non–negative. The default is 0. This attribute is optional.

Search: The scope of the search—where to search for the delimited data. The possible
values are Headers (Search only the headers), Body (search only body data, not
headers), Noresource (search only the HTML body, excluding all headers and
resources), or ALL (search body , headers, and resources). The default value is ALL.

This attribute is optional.

5. When will use lr_start_transaction function ?


The lr_start_transaction function marks the beginning of a transaction. To indicate a
transaction to be analyzed, use the lr_start_transaction and lr_end_transaction
functions. These functions are inserted immediately before and after the transaction.

Transactions can be nested, but each lr_start_transaction statement must be


associated with an lr_end_transaction statement or it will be interpreted as an illegal
command.

Note: Do not use the period character (.) in a transaction or sub-transaction name. The
period character delimits transactions and sub-transactions. In analysis, a transaction
name with a period will be interpreted as two transactions.

6. When will use lr_end_transaction function ?

The lr_end_transaction function marks the end of a transaction and records the amount
of time it took to perform the transaction. To indicate a transaction to be analyzed,
place the lr_start_transaction function before the transaction, and the
lr_end_transaction function after the transaction.

You can manually set the status of the transaction or you can allow the script to detect
it automatically. To manually set the status, you perform a manual check within the
code of your script (see example) evaluating the return code of a function.

For the "succeed" return code, set the status to LR_PASS. For a "fail" return code, set
the status to LR_FAIL. For an "aborted" return code, set the status to LR_STOP.

If status is LR_AUTO, then the value of status is automatically assigned. By default,


this value is LR_PASS signifying a successful transaction. However, if prior to
lr_end_transaction

7. When will use web_reg_find function?

The web_reg_find function registers a request to search for a text string on a Web
page retrieved by the next action function, such as web_url.

This function helps you verify whether or not the page you received is the
desired page by searching for an expected text string.

For example, you can search for the text "Welcome" to check if your home page
opened properly. You can check for the word "Error" to check if the browser
encountered an error.

You can also use this function to register a request to count the number of times the
text appeared.

If the check fails, the error is reported after the next action function executes. This
function only registers requests, but does not perform them. Thus, the return value of
web_reg_find indicates only if the registration succeeded, and not if the check
succeeded.

This function can be used for both HTML–based and URL–based scripts
8 .when will use web_submit_data function?

The web_submit_data function is an action function that performs an "unconditional" or


"contextless" form submission. It allows you to generate GET and POST requests as
made by the HTML forms. You do not need to have a form context to execute this
request.

web_submit_data is recorded only when VuGen is in either the URL–based recording


mode, or in the HTML–based recording mode with the A script containing explicit URLs
only option checked (see VuGen's Recording Options).

The method indicates how the data of the form is sent to the server, whether as a
query within the URL (GET), or as a request body (POST).

This function is generated when VuGen is set to record a Web session in HTTP (all
requests from the server) recording mode. VuGen also records a web_submit_data
statement whenever a form is submitted and it is unable to generate a
web_submit_form statement.

Examples of non–HTML–generated resources are .gif and .jpg images. The List of
Resource Attributes is only inserted when the recording option for these resources is
set at Record within the current script step. This is the default setting. See the HP
LoadRunner Virtual User Generator User Guide.

9. When will use web_submit_data function?

The web find function searches an HTML page for a specified text string. Web _find is
deprecated. It has been replaced with web_reg_find.

This function is limited to HTML–based recorded scripts (see Recording Options >
Recording tab). It searches the context only after the HTML request is complete,
resulting in slower execution time than web_reg_find.

The web find function has been superseded in C Language scripts by


web_reg_find, which runs faster and can be used in both HTML–based and URL–
based recording. web_find is supported in C for backward compatibility. In Java and
Visual Basic, it has not been superseded.

You might also like