lr.set_transaction

Creates a completed transaction.

JavaScript

function lr.set_transaction(  name, duration, status  )

VBScript

Function lr.set_transaction(  name, duration, status  ) 
Transaction Functions

Arguments

NameComments
NameA name for the transaction.
durationTransaction duration in seconds.
statusThe transaction completion status. One of the Transaction Status constants for pass, fail, or stop. The auto status is not applicable.

The lr.set_transaction function creates a transaction, its duration, and status in a single call. Use it where the business process you want to capture in a transaction does not consist of sequential steps, or where you may or may not want to create a transaction, depending on conditions that are known only during the test.

To create a transaction for non-sequential steps, capture the duration of each series of steps that participate in the business process. Sum the durations and create the transaction with lr.set_transaction.

lr.set_transaction can also be used to report the duration of a failed transaction by saving the duration before the transaction fails with lr.get_transaction_duration then using lr.set_transaction to create a new transaction for reporting that time.

lr.set_transaction creates and closes the transaction. Therefore, no functions that work only on open transactions are applicable.

Note: For information on allowed characters and maximum length for transaction names, see Transaction guidelines in the Virtual User Generator Help Center.

Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

Parameterization

All string input arguments can be passed using standard parameterization.

VBScript Example

The follow example shows the capture of transaction duration times based on whether a condition is fulfilled. The start_transaction call creates transaction "Flight". At the point in the transaction where data will be important regardless of the condition, the time is captured with get_transaction_duration. After the ticket and purchase information is submitted, YourAPICall checks whether the submit succeeded. (In this example, YourAPICall simply passes the first iteration and fails the second.)

If YourAPICall determines that the submit successfully caused the server-side action to take place, then get_transaction_duration retrieves the total duration. Because the time spent check on the server if the submit succeeded is not part of the business process, that time is subtracted from the total duration, and set_transaction uses that value to create transaction "SuccessfulFlight". Note that this is the functional equivalent in Visual Basic of the waste time functionality in the C language scripts.

If YourAPICall determines that the server-side action failed, then the value capture with the first call to get_transaction_duration is used by lr.set_transaction to create transaction "FailedFlight".

As a result of this action, analysis data is produced for three transitions.

Transaction "Flight" records an overview of transaction durations for both successful and unsuccessful submit, including the time spent on YourAPICall. Transaction "SuccessfulFlight" records the total end to end times of transactions where the server-side action succeeded, excluding the time spent on YourAPICall. Transaction "FailedFlight" records the time it takes to get the itinerary when then later submit fails.

Below the sample action is the log and the analysis data.

Public Function Action() As Long
Dim trans_time As Double
Dim total_trans_time as Double
Dim rc As Integer
Dim vData As Variant
Dim vOptions As Variant
Dim s_code as Integer
Dim waste_time as Single
Dim start_check as Single
lr.start_transaction "Flight"
vOptions = "Resource=0, " _
    & "RecContentType=text/html, " _
    & "Referer=, " _
    & "Snapshot=t1.inf, " _
    & "Mode=HTML, " _
    & "LAST"
web.URL "flightnet", _
    "URL=http://lazarus/flightnet/" , _
    vOptions
vData = "Name=grpType, Value=radRoundtrip, ENDITEM, " _
    & "Name=lstDepartingCity, Value=Los Angeles, ENDITEM, " _
    & "Name=lstDestinationCity, Value=San Francisco, ENDITEM, " _
    & "Name=txtDepartureDate, Value=1/12/2004, ENDITEM, " _
    & "Name=txtReturnDate, Value=1/14/2004, ENDITEM, " _
    & "Name=txtQuantity, Value=1, ENDITEM, " _
    & "Name=radClass, Value=1, ENDITEM, " _
    & "Name=radSeat, Value=1, ENDITEM, " _
    & "Name=btnAvailableFlights, Value=Next >, ENDITEM, " _
    & "LAST "
web.submit_form "default.aspx" , _
    "Snapshot=t2.inf" , _
    vData
' Get transaction time in seconds for the first part of the transaction: itinerary
trans_time = lr.get_transaction_duration ("Flight")
lr.think_time 3
' Start the second part of the transaction: 
' Choosing a flight and buying a ticket
vData = "Name=lstAvailableFlights, Value=AA6291 Depart 8:10AM, Arrive 11:30AM, $179.47, ENDITEM, " _
    & "Name=btnCustomerInfo, Value=Next >, ENDITEM, " _
    & "LAST "
web.submit_form "default.aspx_2", _
    "Snapshot=t3.inf", _
    vData
vData = "Name=txtCustomerName, Value=Edmund Bertram, ENDITEM, " _
    & "Name=txtAddress, Value=Mansfield Park,\r\n" _
    & "England, ENDITEM, " _
    & "Name=txtPhoneNumber, Value=None, ENDITEM, " _
    & "Name=lstCreditCard, Value=Discover, ENDITEM, " _
    & "Name=txtCardNumber, Value=123456789, ENDITEM, " _
    & "Name=txtExpirationDate, Value=1/1/181, ENDITEM, " _
    & "Name=btnOrderConfirmation, Value=Finish, ENDITEM, " _
    & "LAST"
web.submit_form "default.aspx_3" , _
    "Snapshot=t4.inf" , _
    vData
' The time spent checking the success of the server-side
' action with YourAPICall is not part of the business
' process being tested. Capture the start of the check
' so that the time can be deducted later.
start_check = Timer
' Call the API of your application to see whether the purchase is registered. 
rc = YourApiCall (s_code, "EdmundBertam")
lr.message "After call to YourAPICall, rc = " + Cstr(rc)
' Capture the total time spent on the call to YourApiCall
waste_time = Timer - start_check 
lr.message "Waste time = " + cStr(waste_time)
' If your API confirms success:
If rc = lr.PASS Then
    ' Get the transaction time
    total_trans_time = lr.get_transaction_duration ("Flight")
    ' Deduct the time spent on the call to YourApiCall
    total_trans_time = total_trans_time - waste_time  
    ' Create a transaction for the successful business process
    lr.set_transaction "SuccessfulFlight", total_trans_time, lr.PASS
    lr.Message "API Call succeeded: Record complete duration SuccessfulFlight time = " _
        + Cstr(total_trans_time)
Else
' If your API shows that the process failed:
    ' Use only the time from the start_transaction to the 
    ' first call to lr.get_transaction_duration ("Flight") 
    ' that captured the itinerary section of the business process.     
    ' Create a transaction for the failed business process.
    lr.set_transaction "FailedFlight", trans_time, lr.PASS
    lr.Message "API Call failed: Record duration only up itinerary"
    lr.Message "API Call failed: Record duration only up itinerary. FailedFlight time = " _
        + Cstr(trans_time)
End If
lr.end_transaction "Flight", lr.AUTO
'lr.Message "Duration of logon and itinerary = " + CStr(trans_time)
'lr.message "Return Code is " + lr.eval_string ("<ReturnCode>")
Action = lr.PASS
End Function
Example: Output:
Starting iteration 1.
Starting action Action.
Notify: Transaction Flight started.
web_url("flightnet") was successful, 30710 body bytes, 1982 header bytes
web_submit_form("default.aspx") was successful, 11610 body bytes, 259 header bytes
web_submit_form("default.aspx_2") was successful, 11610 body bytes, 259 header bytes
web_submit_form("default.aspx_3") was successful, 11610 body bytes, 259 header bytes
After call to YourAPICall, rc = 0
Waste time = 2.031875
Notify: Transaction SuccessfulFlight set.
API Call succeeded: Record complete duration SuccessfulFlight time = 3.8044273129425
Notify: Transaction Flight ended with Pass status (Duration: 7.6009 Think Time: 5.0072).
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Starting action Action.
Notify: Transaction Flight started.
web_url("flightnet") was successful, 30710 body bytes, 1982 header bytes
web_submit_form("default.aspx") was successful, 11610 body bytes, 259 header bytes
web_submit_form("default.aspx_2") was successful, 11610 body bytes, 259 header bytes
web_submit_form("default.aspx_3") was successful, 11610 body bytes, 259 header bytes
After call to YourAPICall, rc = 1
Waste time = 2.001469
Notify: Transaction FailedFlight set.
API Call failed: Record duration only up itinerary. FailedFlight time = 0.130188
Notify: Transaction Flight ended with Pass status (Duration: 7.3806 Think Time: 5.0072).
Ending action Action.
Ending iteration 2.

Analysis

When analyzing the four iterations of the script, the following were the results: For two iterations, YourAPICall indicated success, and for two iterations it indicated failure.

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPass
FailedFlight2.5142.7893.0640.2753.0592
Flight8.1129.26310.3550.910.3554
SuccessfulFlight6.697.297.890.57.8892