Lao Li share: LoadRunner with Javavuser for interface testing

Source: Internet
Author: User
Tags throwable

Lao Li share: LoadRunner with Javavuser for interface testing

Here to share a poptest training process in the case, in the daily work will encounter the test system communication is through the encryption of the packet, encryption algorithm is developed by the company itself, and send the packet also to be compressed by the system to ensure the performance of the system. With LoadRunner, there is no way to solve the technical problem of cryptography here, and it would be better to take advantage of the javavuser to develop more sophisticated scripts using Java's more powerful packages.

First step: LoadRunner Create the Java_vuser script:

Select Create/edit script-->new script--> Select Java Protocol-->java_vuser build script in the scripting interface.

Step Two: Configure the LoadRunner environment:

Set classpath in Run-time-setting.

Step three: Import the Java package developed by the company:

As with the Java configuration, there is an import com.lr_class.*, a COM folder in the script directory, in COM in the Add Lr_class folder, the class file to be used.

Step three: Develop Javavuser scripts: scripts with gzip compression and company-developed encryption algorithms.

Note: The HTTP protocol allows the bodybinary parameter in the Web_custom_request function to send a byte stream, or it can be done.


Import LRAPI.LR;
Import com.lr_class.*;
Import Java.io.ByteArrayInputStream;
Import java.io.IOException;
Import org.apache.http.HttpEntity;
Import Org.apache.http.HttpResponse;
Import org.apache.http.client.ClientProtocolException;
Import Org.apache.http.client.methods.HttpPost;
Import org.apache.http.entity.InputStreamEntity;
Import org.apache.http.impl.client.DefaultHttpClient;


public class Actions
{

public int init () throws Throwable {
return 0;
}

public int action () throws Throwable {

String url = "Http://xx.xx.xx.xx/stats/uploadData";

int code;
Byte[] databytes= fdata.putdata ("<testing>", "<user>", "<id>", "<age>", "<time>", 1,1,5,1,1348042886,4,13432909036l,1234567890123455l,1,1);

System.out.println (databytes);
Byte[] B = ungzip.compresstobyte (databytes);
b = Xxxxxrc4.code (b);

System.out.println (b);
Lr.start_transaction ("send");
Bytearrayinputstream bs = null;
BS = new Bytearrayinputstream (b, 0, b.length);
HttpPost HttpPost = new HttpPost (URL);
Httppost.addheader ("Content-type", "Application/octet-stream");
Httpentity he = new Inputstreamentity (BS, b.length);
Httppost.setentity (He);
HttpResponse HttpResponse = new Defaulthttpclient (). Execute (httppost);
Code = Httpresponse.getstatusline (). Getstatuscode ();

if (code = = 901) {
Lr.output_message ("Success Code:" +code);
Lr.end_transaction ("Send", LR. PASS);
}
else{
Lr.error_message ("Failure Code:" +code);
Lr.end_transaction ("Send", LR. FAIL);
}
return 0;
}


public int End () throws Throwable {
return 0;
}
}

Original link: http://www.cnblogs.com/laoli0201

Lao Li share: LoadRunner with Javavuser for interface testing

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.