How to insert transactions in QTP?

In this blog post, we will see about how to insert transactions in QTP.

What is Transaction?

The total time taken to execute the script gets generated in the HP Results file, once QTP completes its execution. But your clients are asking you to measure the time of each action or each business flow of your script execution.

By inserting transactions in your QTP script, you can measure the time taken for your script sections. You can insert any number of transactions in your QTP script. But start and end transactions should match.

E.g. To measure how long will it take to complete following business flows, you need to insert transactions at respective steps.

  • 01_FlightLogin
  • 02_BookingTicket
  • 03_FlightLogOff

If you observe the above snapshot, there are statements under Login and Flight Reservation such as Services.StartTransaction and Services.EndTransaction.

How to insert transactions in QTP?

There are two ways to insert transactions:

  • During recording
  • After recording

We will see how to insert transactions during recording. Click on Record button to start recording, before you perform any action on application under test (AUT), i.e. Flights, go to Insert > Start Transaction as shown below.

 

Start Transaction dialog box opens up. Enter a valid name to your transaction as shown below. Click on OK to insert.

Now, perform your actions on Flights. Once you completed, you need to end your transaction by navigating Insert > End Transaction. End Transaction dialog box opens up which lists all the transactions. Select your right transaction, and then click on OK.

Similarly repeat above steps for 02_BookingTicket and 03_FlightLogOff. Stop your recording session. In the expert view you could see below code.

Services.StartTransaction "01_FlightLogin"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Password:").SetSecure "50d1aa6999d71657f5dc8845edd553549a779117"
Dialog("Login").WinButton("OK").Click
Services.EndTransaction "01_FlightLogin"

Now we will see how to insert transactions after recording.

Insert transactions in QTP after recording

Navigate to appropriate steps in your script and insert below code to start transaction.
Services.StartTransaction "your_transaction_name"
To end transaction, insert below code.
Services.EndTransaction "your_transaction_name"

Please note start and end transaction names should match. If there is any conflict, QTP will not generate transaction results.

How to insert nested transactions in QTP?

Now we will see how to insert nested transactions.
Services.StartTransaction “Parent_transaction_name"
Services.StartTransaction "First_nest_transaction_name"
Your code …
Your code …
Your code …
Services.EndTransaction " First_nest_transaction_name"
Services.StartTransaction "Second_nest_transaction_name"
Your code …
Your code …
Your code …
Services.EndTransaction " Second_nest_transaction_name"
And so on …
Services.EndTransaction "Parent_transaction_name”

Transactions in QTP Results

Now we will see how to see the time taken for the transactions we created. Once the execution gets completed, open the QTP results. Click on End Transaction : 01_FlightLogin, in right side you could see the time taken for Flight Login transaction. See below snapshot for reference.

QTP took 0.3594 seconds to login into Flight application.

I hope this article explained what transaction is and how to insert transactions in HP QuickTest Pro.

Happy Testing!

Thanks for visiting QAInsights!

We’re always posting interesting articles on QAInsights. I request you to subscribe so you don’t miss out anything.

Subscribe to our QAInsights YouTube Channel. Subscribe our free weekly newsletter or Google feeds.

About the Author

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link