Java user script development of LoadRunner

Source: Internet
Author: User
Tags throwable

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. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.