How to use Transactions in QTP/UFT
โก Smart Summary
Transactions in UFT One measure how long a chosen section of a test takes to run, by wrapping those steps between a start statement and an end statement that reports the duration in the run results.
In UFT One/QTP, You can measure how long it takes to run a section of your test by defining Transactions. You define transactions within your test by enclosing the appropriate sections of the test with start and end transaction statements.
Transactions can be inserted anywhere in the script, and there is no limit to the number of transactions that can be added to a test.
⚠️ Product naming: the tool shipped as HP QuickTest Professional (QTP), became HP and then Micro Focus Unified Functional Testing, and is sold today by OpenText, whose current help pages call it OpenText Functional Testing. Transactions work the same way in every one of those releases.
How to insert transactions in QTP?
You can also insert a transaction within a transaction
Following video takes you through the steps to insert a Transaction in UFT One.
Click here if the video is not accessible
For example, you may want to note the time taken to book a flight.
- In QTP, select the appropriate state where you want to start your transaction.
- Select Insert Start Transaction. Start Transaction Dialog Box opens
- Give the transaction a suitable name, say “Booking Time”
- A start transaction statement is added in the test
- Select the state where you want to end the transaction
- Click Insert > End Transaction
- End Transaction Dialog Box Opens with the list of all available transactions
- Click Okay. An end transaction statement is added
- Let’s run the test
- In results, the end transaction statement gives the time taken to insert the order
Note: the same dialog boxes are reached from the Keyword View, and the Step Generator inserts the identical statements without opening the Insert menu.
Transaction Statements in the Editor
The dialog boxes above write two VBScript lines into the test. Typing them yourself in the Editor is faster once the pattern is familiar, and it is the only option when the steps are generated by code.
Services.StartTransaction "Booking Time" ' the steps that book the flight go here Services.EndTransaction "Booking Time"
Both methods belong to the Services object. The start statement takes one argument, the end statement takes an optional second one.
| Statement | Arguments | What it does |
|---|---|---|
| Services.StartTransaction | Name | Begins the time measurement at that point in the run |
| Services.EndTransaction | Name, [Status] | Stops the measurement and records the result |
The optional status decides how the transaction is graded. Leaving it out is the same as passing Auto.
- Auto โ passes unless an error occurred between the two statements. This is the default.
- Pass โ always ends with a Pass status.
- Fail โ always ends with a Fail status.
Services.StartTransaction "Booking Time" Wait 1 Services.EndTransaction "Booking Time", Pass
Reading Transaction Results
Once the test finishes, the End Transaction step in the run results carries four values that explain the measurement.
| Result field | Meaning |
|---|---|
| Transaction name | The name supplied in the start statement |
| End status | Pass or Fail, decided by the status argument or by Auto |
| Total duration | Elapsed time between the start and end statements |
| Wasted time | Time inside the duration that UFT One itself added |
Wasted time matters because the tool runs background processes while the transaction is open. Subtract it from the total duration to estimate what the application alone would have taken, which is the number worth comparing between builds.
A single-user duration is a functional benchmark, not a load figure. Concurrency is measured by a performance testing tool, and a transaction that is fine for one user can still collapse under a hundred.
Nested and Distributed Transactions
The source step list notes that a transaction can sit inside another one, which is how a slow sub-step is isolated without losing the timing of the whole flow. The outer transaction keeps running while the inner one opens and closes.
Two rules keep nesting safe.
- Every name needs a matching pair, and the start statement must appear before its end statement.
- Only one transaction with a given name may be open at a time. Opening a second one with the same name ends the first with a Fail status.
A distributed transaction goes further and spans two tests: Services.StartDistributedTransaction opens it in the first test and Services.EndDistributedTransaction closes it in the second, matched by a unique ID rather than by name. It exists for Business Process Monitor and LoadRunner scenarios, which read only the data recorded inside a transaction and ignore everything outside one.
When a step inside a transaction can legitimately fail, pair the transaction with a recovery scenario so the run reaches the end statement instead of stopping halfway.
