lr_end_transaction Function in LoadRunner With Example

In this Loadrunner Tutorial, you will learn about lr_end_transaction. To understand this function first of all, we should understand what is transaction. We can say that transactions are mechanics to measure server response time for any operation. In other words, we can say that we can use transaction to measure the time taken by the system for a particular request. It can consist of a single task or group of tasks in the request.

It is very easy to apply and use transaction in the script. We just need to write one line of code before request is made to the server and close the transaction when the request ends. We only need to give transaction name to a particular request. Let’s see it one by one. To open a transaction, we can use this line

lr_start_transaction(“Transaction Name”);

To close the transaction, we can use this line of code, as given below:

lr_end_transaction(“Transaction Name”, <status>);

Status is important thing to understand in the function  lr_end_transaction because it is used to tell LoadRunner whether this particular transaction should be successful or unsuccessful after execution of code block inside transaction. The possible parameters could be:

  • LR_AUTO
  • LR_PASS
  • LR_FAIL

Let us understand with the help of example. Different types of Status denotes how we want to close the transaction. Let us see the following example to understand it in better way.

Action()

{

//Starting one  transaction. The name of transaction is Open_Link

lr_start_transaction(“Open_Link”);

//// opening website google.com

web_url(“www.google.com“,

“URL=http://www.google.com/“,

“Mode=HTML”,

LAST);

//Sending transaction with Pass status which means that if the code inside the transaction is //executed successfully, it will give Pass status in the output log window of LoadRunner.

lr_end_transaction(“Open_Link”, LR_PASS);

                return 0;

}

We can see the same code given above in the form of screenshot which is given below.

lr_end_transaction Example1

Output of the code is known as given below. We can see clearly in the output log of LoadRunner that transaction is ending with Pass status.

Action.c(4): web_url(“www.google.com“) was successful, 130836 body bytes, 2683 header bytes, 698 chunking overhead bytes                 [MsgId: MMSG-26385]

Action.c(8): Notify: Transaction “Open_Link” ended with a “Pass” status (Duration: 1.8527 Wasted Time: 0.2742).

Ending action Action.

We can clearly see the message that transaction has ended with Pass status and also “duration” is being shown in the log window of LoadRunner. Message text has been highlighted which can be seen as given below, in the form of screenshot.

lr_end_transaction Example 2

We can see the highlighted portion of the output log window of LoadRunner, in the form of screenshot given below, which is showing transaction status and duration of transaction which helps us to determine the time taken to execute the transaction.

lr_end_transaction Example 3

One thing to note here is that we will get Pass status after successful execution of the code when the status is changed to set to LR_AUTO in the function lr_end_transaction.

Action()

{

lr_start_transaction(“Open_Link”);

web_url(“www.google.com“,

“URL=http://www.google.com/“,

“Mode=HTML”,

LAST);

lr_end_transaction(“Open_Link”, LR_AUTO);

                return 0;

}

We can see the same result which is given as below. We can clearly see that output log window of LoadRunner contains message that transaction has ended with status Pass along with duration information when the status has been set to LR_AUTO, which we can see in the code above.

Action.c(4): web_url(“www.google.com“) was successful, 130563 body bytes, 2683 header bytes, 669 chunking overhead bytes                 [MsgId: MMSG-26385]

Action.c(8): Notify: Transaction “Open_Link” ended with a “Pass” status (Duration: 2.3505 Wasted Time: 0.5824).

Now let us see the transaction where we want return status as Fail. Let us see the code below.

Action()

{

lr_start_transaction(“Open_Link”);

web_url(“www.google.com“,

“URL=http://www.google.com/“,

“Mode=HTML”,

LAST);

lr_end_transaction(“Open_Link”, LR_FAIL);

                return 0;

}

We can see the same code in the form of screenshot given below.

lr_end_transaction Example 4

We can clearly see that output log window of LoadRunner is showing the transaction status as Fail. Also showing the duration of the transaction. Also, it is showing that there has not been any error in the script. Let us see the main part of output log window of LoadRunner as given below.

Action.c(4): web_url(“www.google.com“) was successful, 130560 body bytes, 2683 header bytes, 736 chunking overhead bytes                 [MsgId: MMSG-26385]

Action.c(8): Notify: Transaction “Open_Link” ended with a “Fail” status (Duration: 2.0077 Wasted Time: 0.3643).

Action.c(8): Notify: Transaction “Open_Link” has 0 error message(s).

Let us see the output window of LoadRunner, after execution of the above code, in the form of screenshot given below

lr_end_transaction Example 5

Let us see the highlighted portion in the screenshot given below which gives clear picture of transaction status and duration.

lr_end_transaction Example 6

Overall, we can say that it is a very useful function to end the transaction with proper status and help us in understanding the response time of the transaction/ scenario.

Go to this page for more Loadrunner Functions with Examples