LoadRunner – Transaction Handling

A transaction defines a set of end-user actions that represent the real user activities on an application. A transaction can have multiple requests or sequences of actions that hit the server at a predefined rate (SLA). 

In terms of Micro Focus LoadRunner, transactions are used to measure the performance of the server. Each transaction measures the time it takes for the server to respond to specified Vuser requests. These requests can be simple tasks such as waiting for a response for a single query, or complex tasks, such as submitting several queries and generating a report.

A LoadRunner script can have an unlimited number of transactions/sub-transactions with a different name. Ideally, each user action should be captured in an individual transaction. Example: login, search, submit an order, logout, etc. Each transaction has its own section fenced by the start and end transaction function. The controller measures the response time of a transaction starting from sending a request to the server to getting the full response from the server.

LoadRunner - Transaction Handling - Response Time
Figure 01: LoadRunner Transaction Response Time

How to insert transactions in the LoadRunner script?

There are 2 ways to insert transactions into the script.

1. While recording: When you start recording a script, you can see the ‘Insert Start Transaction’ button on a floating toolbar.

LoadRunner Insert Start Transaction Option
Figure 02: Insert Start Transaction

Click on ‘Insert Start Transactions’ or press the ‘Ctrl+T’ button from the keyboard, add the transaction name and click ‘OK’

LoadRunner Add Transaction Name
Figure 03: Add Transaction Name

Once you click ‘OK’, the ‘Insert End Transaction’ button will be enabled.

LoadRunner Insert End Transaction Option
Figure 04: Insert End Transaction

Click ‘Insert End Transaction’ or press ‘Ctrl+Shift+T’ to end the transaction. After clicking on ‘Insert End Transaction’ you will see a list of started transactions, choose the one which you want to end. This option helps to avoid the error of open transactions.

LoadRunner Started Transactions
Figure 05: Started Transaction List

Likewise, you can insert sub-transactions (i.e. one transaction within another transaction). Just make sure you follow the correct sequence of ending the transaction

Transaction vs Sub-transaction
Figure 06: Transaction vs Sub-transaction

2. After recording: Right-click on the script where you want to start the transaction, then either hover ‘Insert’ or click ‘Start Transaction‘. 

Start Transaction
Figure 07: Add Transaction

or Select Design > Insert in Script > Start Transaction

Start Transaction
Figure 08: Add Transaction from Design Tab

or press ‘Ctrl+T’

The result of the above-mentioned step is that VuGen inserts an lr_start_transaction(“”); function into the Vuser script. You can add the transaction name as an argument of the function, like lr_start_transaction(“Login”). To end the transaction follow the same steps and choose ‘End Transaction’.

Note:

  • The transaction name should be exactly the same in the ‘lr_start_transaction’ and ‘lr_end_transaction’ function.
  • Avoid using a “. (period)”, “@ (at the rate)”, “: (colon)”, “< > & | (comparison/conditional operators)” or “, (comma)” symbol in a transaction name. These characters may cause errors to occur when attempting to open the Analysis Cross Results graphs.
  • A failed transaction does not automatically set the script’s Replay status to Failed.
  • Do not add think time, rendezvous point and flow logic inside a transaction.

Description of functions:

1. lr_start_transaction: This function starts a specified transaction in the script. The argument is considered as a string with the integer return type. This function returns 0 if it succeeds. It returns -1 if the transaction name is illegal.

2. lr_end_transaction: This function ends a specified transaction. The argument of transaction name is considered as a string and status is considered as an integer. This function returns 0 if it succeeds. It returns -1 if the transaction name is illegal or if there is no prior call to lr_start_transaction with a transaction of the same name. 
You can manually set the status of the transaction or you can allow the script to detect it automatically.

  • LR_PASS: Success (return 0)
  • LR_FAIL: Failure (return 1)
  • LR_AUTO: The value of status is automatically assigned. By default, this value is LR_PASS signifying a successful transaction (return 2)
  • LR_STOP: Aborted (return 3)

Example:

lr_start_transaction(“01_HomePage”);
status = site_active();
if (status == 0)
    lr_end_transaction(“01_HomePage”, LR_PASS);
        else
    lr_end_transaction(“01_HomePage”, LR_FAIL);


You may be interested: