Loadrunner中java Vuser协议脚本开发
Loadrunner支持很多协议,其中java Vuser协议也是测试中常用一种协议。
准备:
在使用要java Vuser协议,需要安装jdk,配置jdk环境变量。
注意:目前loadrunner 11,只支持jdk 1.6以下版本,否则会报如下错误:
Error: Java VM internal error:Error Loading javai.dll.
Error: Thread Context: Call to service of the driver failed, reason - thread context wasn't initialized on this thread.[MsgId: MERR-10176]
脚本介绍:
使用java Vuser协议脚本,其实可以先使用eclipse工具开发和调试好脚本,然后复制到LR运行, LR中对java编码还没有eclipse方便。
默认java Vuser脚本如下:
import lrapi.lr;
public class Actions
{
//此init方法是对应c语言时vuser_init文件,方法名不能修改
public int init() throws Throwable {
return 0;
}//end of init
//对应c语言时action文件
public int action() throws Throwable {
return 0;
}//end of action
//对应c语言时vuser_end文件
public int end() throws Throwable {
return 0;
}//end of end
}
使用技巧:
a.使用java vuser时加载其它第三方jar包或者自定义jar时,
1.在runner-setting进行配置
2.直接在action中,import 对应包及可在代码中直接调用jar包中方法。
eg: import com.ibm.mq.*;
b.在running-setting也可以手动指定jdk路径。