LoadRunner手动编写http请求示例(同样试用于TCP及其它的性能测试脚本)

1.将原有的请求方法进行封装(Post/Get)打包成相应的jar包,编译、打包选择的jdk版本为1.6,否则会导致生成的jar包不能在LR中跑起来


备注:此处为反编译后显示的代码

2.手动编写请求脚本

GET 请求:

import java.util.HashMap;
import java.util.Map;
import lrapi.lr;
import com.hzins.pluto.HttpPost_Method;
import com.hzins.pluto.HttpGet_Method;

public class Actions
{
	String Detail="http://xxx.xxx.xxx/product/detail-500.html";
	HttpGet_Method get =null;


	public int init() throws Throwable {
	      get=new HttpGet_Method();
		return 0;
	}//end of init


	public int action() throws Throwable {
	    String response3=get.do_httpget(Detail,null);

	     lr.output_message("response3:"+response3);
		return 0;
	}//end of action


	public int end() throws Throwable {
		return 0;
	}//end of end
}
Post请求

import java.util.HashMap;
import java.util.Map;
import lrapi.lr;
import com.hzins.pluto.HttpPost_Method;


public class Actions
{
    String GetProductSellCount="http://xxx.xxx.xxx/Public/GetProductSellCount";
    HttpPost_Method post=null;

	public int init() throws Throwable {
              post=new HttpPost_Method();
		return 0;
	}//end of init


	public int action() throws Throwable {
            lr.start_transaction("schedule");
            Map<String, String> nameValuePairs2 = new HashMap<String, String>();
            nameValuePairs2.put("productId", "500");
	    String response2=post.do_post(GetProductSellCount, nameValuePairs2);
            lr.output_message("response:"+response2);

            if (response2.contains("Count"))
		lr.end_transaction("schedule", 0);
	    else {
		lr.end_transaction("schedule", 1);
	    }

	    lr.think_time(1);
		return 0;
	}//end of action


	public int end() throws Throwable {
		return 0;
	}//end of end
}

3.将jdk包和依赖包加载到LR的运行目录


4.运行脚本

Post执行后的结果:

Virtual User Script started at : 2016-03-31 09:23:12
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
Notify: Transaction "schedule" started.
response:"[{\"Id\":500,\"Count\":2238}]"
Notify: Transaction "schedule" ended with "Pass" status (Duration: 0.3856).
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

下载Lr.jar包,方便在Eclipse中编写代码,将代码COPY到LR中进行编译和调试,LoadRunner只支持JDK1.6 32位,否则会执行不过

http://download.csdn.net/detail/u011053107/8166389

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值