Sunday, April 15

Rational Performance tester(RPT) custom code to log user value fom datapool


Below is the custom code in Rational Performance tester that I managed for logging username value from datapool into test log. In Loadrunner, very often one uses commands like lr_message,lr_log_message to log username that was used by a particular virtual user in particular iteration. This helps performance tester to check whether the data was used was appropriate one, of if error occured, then what was the data used by the users etc. This this can be achieved in RPT by writing custom java code.
Custom  Code class implements interface ICustomCode which has method called exec with method parameters of object type ITestExecutionServices and type String array
The trick is understand the classes/method/interfaces of this Interface ITestExecutionServices. This object has information about a virtual user in interface name IDataArea . Below is the syntax to retrieve this Virtual user dataarea.


IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER);

From this Interface, one has to get another interface instance named IVirtualUserInfo. This interface contains that virtual user information.Below is the syntax code for that

IVirtualUserInfo virtualUserInfo = (IVirtualUserInfo) dataArea.get(IVirtualUserInfo.KEY);

And then from this Interface, one can get virtual userID by method named called getUserName()
To log he datapool value of user actually used , I passed that datapool value as argument to custom code interface. Since it was only one argument passed, I was able to extract the value of it in custom code by code syntax 'String UserName = args[0];' . Below is the complete code  for this custom code interface

package customcode;
import com.ibm.rational.test.lt.kernel.IDataArea;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.services.IVirtualUserInfo;
/**
* @author unknown
*/
public class LogUserName implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public LogUserName() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
String UserName = args[0];
IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER);
IVirtualUserInfo virtualUserInfo = (IVirtualUserInfo) dataArea.get(IVirtualUserInfo.KEY);
String User = virtualUserInfo.getUserName();
tes.getTestLogManager().reportMessage(User + "=" + UserName);
return null;
}
}


No comments:

Post a Comment

---------------------------------------------

Related Posts Plugin for WordPress, Blogger...