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;importjava.io.OutputStreamWriter;importjava.net.URL;importjava.net.URLConnection;importlrapi.lr;publicclassActions{ publicintinit() throwsThrowable { return0; }//end of init publicint action() throwsThrowable { /***访问首页事务*/ lr.start_transaction("访问poptest首页"); String serverUrl="http://www.poptest.cn/";//请求页面url路径 OutputStreamWriter out =null; try{ URL url =newURL(serverUrl); URLConnection conn = url.openConnection();.//建立连接 conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Content-Type","UTF-8");//设置请求字符编码 out=newOutputStreamWriter(conn.getOutputStream(),"UTF-8");//设置回应字符编码 out.flush(); out.close(); InputStream in =conn.getInputStream(); byte[] buffer= newbyte[in.available()]; in.read(buffer); System.out.println(newString(buffer)); } catch(Exception e ) { e.printStackTrace(); }finally{ if(out!=null){ try{ out.close(); } catch(Exception e ) { e.printStackTrace(); } } } lr.end_transaction("访问poptest首页", lr.AUTO); return0; }//end of action publicint end() throwsThrowable { return0; }//end of end}4. Compile 5. Execute 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.
Java user script development of LoadRunner