By This email address is being protected from spambots. You need JavaScript enabled to view it.


IBM Tivoli Composite Application Manager for Reponse Time (ITCAMfRT) supports the running of robotic transactions recorded using Rational Performance Tester (RPT).

RPT is an Eclipse-based tool that can record HTTP traffic from a web browser, and play it back, subjecting the transactions to numerous tests. One of RPT's strengths is that it supports the integration of custom code into the playback process, thus giving great flexibility in handling complex monitoring requirements.

This article will illustrate creating a custom code hook in an RPT script to process the content of a page that will, in turn, fire situation to the Tivoli Enterprise Portal (TEP) on failure.


This article assumes a familiarity with:

  • Rational Performance Tester
  • Java coding

Recording the Test

For this tip, we are using the WebSphere sample application, Plants for WebSphere. A simple scenario of adding an item to the shopping cart, increasing the number of items and recalculating the price is recorded:

shopping cart

We are going to write some code to check that the recalculated price is correct for this item. This is a slightly convoluted example, but provides a suitable scenario where custom code is applicable as the HTML requires pulling apart and subjecting to some logic in order to meet this requirement.

For details on using RPT to record HTTP transactions, following the Hello, World tutorial at

Adding the custom code hook

To add our custom code:

Find the page with the HTML to process:

html find

Right Click ->Add->Custom Code:

custom code add

Give the class a meaningful name; e.g. test.PriceCalcCheck and press <Generate Code>

Passing the page content to the code

To get the code to process the page, we need to create a field reference and pass it as an argument:

Select the Response: 200 - OK section of the page in the Test Contents tree. Right-click Contents and select Create Field Reference:

create field ref

Select Custom code: test.PriceCalcCheck in the Test Contents tree and press <Add> in the Arguments section:

create arg 1

Find the URL of the page and select Reference: Entire "Content" field and press <OK>:

create arg 2

Processing the content and raising a situation

Open the generated file. We need to add the following methods:

Obtaining price information from the page:

private int getItemQuantity(final String page) {
String token = findToken(page,
"name="itemqty0" size=d+ maxlength=d+ value=d+", "value=");
return (token != null) ? Integer.parseInt(token) : -1;

private double getItemCost(final String page) {
String token = findToken(page, "PRICE.*?$d.dd", "$");
return (token != null) ? Double.parseDouble(token) : -1;

private double getPageTotal(final String page) {
String token = findToken(page, "Order Subtotal:$d.dd", "$");

return (token != null) ? Double.parseDouble(token) : -1;

A regular expression helper to find page items:

private String findToken(final String page, final String regEx, final String tokenStart) {
Pattern CRLF = Pattern.compile(regEx);
Matcher m = CRLF.matcher(page);

String result = null;
if (m.find()) {
String match =;
int start = match.indexOf(tokenStart) + tokenStart.length();
result =, match.length()).trim();


return result;

A generic method to fire the ITM 6 situation:

private void fireSituation(final ITestExecutionServices tes,
final String details, final String expected, final String actual) {

// Create a new event that will cause the situation RRT_Playback_Error to fire
VerdictEvent ve = new VerdictEvent();
ve.setCausedBy("Cause by test.PriceCalcCheck");

// Set RRT_Playback_Error Additional Details attribute

EventProperty ep1 = new EventProperty();
// Set RRT_Playback_Error Expected Value attribute

// Set RRT_Playback_Error Violated Value attribute
EventProperty ep2 = new EventProperty();

// Fire the situation

And finally, replace the content of the exec() method to call our code:

// Get the HTML of the page - this is the "Entire Content Field" reference we created
String page = args[0];

// Remove all line breaks from HTML otherwise regular expressions over multiple lines will not match
page = page.replaceAll("n", "");

// Get the count of the cart item
int itemQuantity = getItemQuantity(page);

// Get the cost of one item
double itemCost = getItemCost(page);

// Get the total price as calculated by the application
double pageTotal = getPageTotal(page);

if (itemQuantity != -1 && itemCost != -1 && pageTotal != -1) {

// Is the displayed total correct - if not, fire situation
if (itemQuantity * itemCost != pageTotal) {
fireSituation(tes, "Cart price recalculation is wrong!.", String
.valueOf(itemQuantity * itemCost), String.valueOf(pageTotal));

} else {
fireSituation(tes, "Failed to obtain test data from page.",
"valid item quantity, item cost and total", itemQuantity + ", "
+ itemCost + ", " + pageTotal);

return null;

The entire source file is here.

Finally upload the script to the Dashboard Agent and deploy it to a robotic agent using a playback situation.

Viewing the situation results

When the price is incorrect, our code fires the RRT_Playback_Error situation that we can see in the TEP:

tep alert 1

tep alert 2 detail

Debugging Code

When developing RPT custom code, the logging facility can prove useful for debugging. Simply add the following line when a trace message is required:

tes.getTestLogManager().reportMessage("My message goes here");

When the robotic script is ran inside RPT as a performance test, the Test Log contains a message element for each debug statement we add:

debug message in log

Wrap up

This tip illustrates the basics of hooking Java code into RPT scripts to allow flexible monitoring of page content and raising alerts inside ITM 6.

Twitter Feed

OrbData So proud to be Partnered with this global brand @ibm Putting Smart to Work!! #thinklondon #putsmarttowork


100 Longwater Avenue, Green Park, Reading, RG2 6GP, U.K.
+44 (0) 118 945 0130
This email address is being protected from spambots. You need JavaScript enabled to view it.

markerFind on Google Maps

About Us

Orb Data brings together People, Process and Technology to deliver the cornerstone of business success: the management of IT infrastructure. At our heart are our people. We have unrivalled experience, helping us to achieve an enviable reputation for excellence in project delivery. Because we’re independent, we identify actual issues and help organisations resolve them –from spec to deployment, and beyond –providing the right solution in terms of best of breed technology and support. We offer a refreshingly simple approach to the way we conduct business. We take pride in our abilities to provide first class solutions to business problems, and to conduct working relationships with honesty and integrity.

Follow Us On: