Lao Li share: LoadRunner Java User script development

Source: Internet
Author: User
Tags throwable

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

 *                    

 */

importjava.io.InputStream;

importjava.io.OutputStreamWriter;

importjava.net.URL;

importjava.net.URLConnection;

importlrapi.lr;

publicclassActions

{

    publicint init() 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. 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

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.