Javavuser Script Development-Environment building

Source: Internet
Author: User
Tags throwable

As is known to all, LoadRunner can perform performance tests using a variety of protocols. The Javavuser protocol has to be mentioned here.

Are you tired of it? In LoadRunner script development, using various C functions for complex string concatenation, parsing the message?

So why not use the Javavuser protocol provided by LoadRunner to develop Java-based scripts.

1. Prerequisites

Scenarios where you can directly use the logic code provided by Java.

2. Environment

loadrunner11.0

Jdk1.6.32_x86_32

3. Create a new script

Select the Javavuser protocol

4. Setting up the Java environment

Vuser--runtime Settings

5. Writing Javavuser Scripts

The following script mainly simulates accessing an app's page through a URL path, and returning to the homepage content.


/* * LoadRunner Java script.                      (Build: _build_number_) * * Script description:javavuser access page * * Creator:jeffsui * * Create time:2014-04-15 * */import java.io.inputstream;import java.io.outputstreamwriter;import Java.net.url;import java.net.URLConnectio N;import lrapi.lr;public class Actions{public int init () throws Throwable {return 0;}    End of Initpublic int action () throws Throwable {/*** Access Home transaction */lr.start_transaction ("Access Gitbucket Home");    String serverurl= "Http://localhost:8026/gitbucket";//Request page URL path outputstreamwriter out =null; try {URL url =new url (serverurl); URLConnection conn = Url.openconnection ();. Establish connection conn.setdoinput (true); Conn.setdooutput (true); Conn.setrequestproperty ("Content-type", "UTF-8");// Set the request character encoding Out=new OutputStreamWriter (Conn.getoutputstream (), "UTF-8");//Set the response character encoding Out.flush (); Out.close (); I Nputstream 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 ("Access Gitbucket Home", LR. AUTO); return 0;} End of Actionpublic int end () throws Throwable {return 0;} End of End}


6. Compiling


Compiled by


No Errors Detected




7. Execute the Script


Starting Iteration 1.Starting action Actions.Notify:Transaction "visit Gitbucket Home" started.//home content omitted .... Notify:transaction "Access Gitbucket home" ended with "Pass" status (duration:4.9907).
8. Problems encountered

(1) Currently LOADRUNNER11 only supports 32-bit JDK, remember

(2) Runtimesettings just loads the base JDK, and if you need to load other third-party jar packages, load them in javafunction

(3) Javavuser's execution efficiency depends on your Java code, minimizing LoadRunner intervention.





Javavuser Script Development-Environment building

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.