Lao Li share: LoadRunner Java User script development
Poptest in the performance Test LoadRunner course, the main web protocol, but also the other protocol script development, for a performance test engineer need to master more than one protocol, here you can see how Javauser script development environment to build.
A friend who is familiar with Java, can call Javauser directly to parse protocol messages and handle logical requests.
Scripting Development Environment:
loadrunner11.0
Jdk1.6.32_x86_32
Scripting development
1. Select the Javavuser protocol
2. Configuring the Java Environment (Vuser--runtime Settings)
3. Developing Javavuser Scripts
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description: JavaVuser访问页面
*
* creator:jeffsui
*
* Create Time:2015-09-28
*
*/
import
java.io.InputStream;
import
java.io.OutputStreamWriter;
import
java.net.URL;
import
java.net.URLConnection;
import
lrapi.lr;
public
class
Actions
{
public
int
init()
throws
Throwable {
return
0
;
}
//end of init
public
int
action()
throws
Throwable {
/***访问首页事务*/
lr.start_transaction(
"访问poptest首页"
);
String serverUrl=
"http://www.poptest.cn/"
;//请求页面url路径
OutputStreamWriter out =
null
;
try
{
URL url =
new
URL(serverUrl);
URLConnection conn = url.openConnection();.
//建立连接
conn.setDoInput(
true
);
conn.setDoOutput(
true
);
conn.setRequestProperty(
"Content-Type"
,
"UTF-8"
);
//设置请求字符编码
out=
new
OutputStreamWriter(conn.getOutputStream(),
"UTF-8"
);
//设置回应字符编码
out.flush();
out.close();
InputStream in =conn.getInputStream();
byte
[] buffer=
new
byte
[in.available()];
in.read(buffer);
System.out.println(
new
String(buffer));
}
catch
(Exception e ) {
e.printStackTrace();
}
finally
{
if
(out!=
null
){
try
{
out.close();
}
catch
(Exception e ) {
e.printStackTrace();
}
}
}
lr.end_transaction(
"访问poptest首页"
, lr.AUTO);
return
0
;
}
//end of action
public
int
end()
throws
Throwable {
return
0
;
}
//end of end
}
4. Compiling
5. Execute the Script
Poptest Experience Sharing:
(1) Loadrunner11 only supports 32-bit JDK
(2) Runtimesettings just loads the base JDK, and if you need to load other third-party jar packages, load them in javafunction
(3) The execution efficiency of Javavuser depends on your Java code.
Poptes do T is the only test development training institutions, website address www.poptest.cn, the course consultation please add qq:564202718
http://www.cnblogs.com/laoli0201
Lao Li share: LoadRunner Java User script development