码迷,mamicode.com
首页 > 编程语言 > 详细

LoadRunner + java脚本 第三章

时间:2015-09-19 16:34:21      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

1.Java Vuser 模板脚本如下:

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */

import java.util.HashMap;

import com.Interface.FilmNews;
import com.Interface.Plans;
import com.vug.Vug;

import lrapi.web;
import lrapi.lr;

public class Actions
{
	public static String uid = "ko";
	public static String Md5Key = "jj";
	public static String filmHost = "http://115.28.1/cias_web/server";
	public static String planHost = "http://115.28.1/order/server";

	HashMap<String, String> params;
	Vug vug; // 构建生成url
	FilmNews fn; // 影讯接口
	Plans pn; //订单接口

	public int init() throws Throwable {
	    vug = new Vug(uid, Md5Key);
	    params = new HashMap<String, String>();
	    fn = new FilmNews(uid);
//	    pn = new Plans(uid);
	    return 0;
	}//end of init


	public int action() throws Throwable {

	    	params = fn.cinemas(); // 要测试的接口

		String url = vug.getURL(filmHost, params);

		lr.start_transaction("test");

		lr.think_time(1); 

		web.reg_find("Text=errCode\":0", 

		new String[]{ 

		    "SaveCount=errCode", 

		    web.LAST 

		}); 

		web.reg_save_param("all", 

		new String []{ 

		    "LB={\"cinemaId\":",  

		    "RB=,", 

		    "Search=Body",
		    
		    "ORD=ALL",

		    "LAST"}); 


		web.url("test",

		"URL=" + url,

		new String[] {

		    "TargetFrame=",

		    "Resource=0",

		    "RecContentType=text/html",

		    "Mode=HTML",

		    "LAST"

		});
		
/*		params = pn.orderadd("<test>", "<test1>", "<test2>");
		url = vug.getURL(host, params);

		web.url("test",

		"URL=" + url,

		new String[] {

		    "TargetFrame=",

		    "Resource=0",

		    "RecContentType=text/html",

		    "Mode=HTML",

		    "LAST"

		});
*/		

		if (lr.eval_int("<errCode>") == 1 ) {

		    lr.end_transaction("test", lr.PASS);
			
		} else {		    
		    lr.error_message(lr.eval_string("<all_1>"));
		    lr.end_transaction("test", lr.FAIL);
		}
		return 0;
	}//end of action


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

 2.上述脚本在Controller中测试通过,另LR11的最多支持1000java vuser虚拟用户,License如下:
golba-100: AEAMAUIK-YAFEKEKJJKEEA-BCJGI
golba-1000:AEACFSJI-YASEKJJKEAHJD-BCLBR
web-10000: AEABEXFR-YTIEKEKJJMFKEKEKWBRAUNQJU-KBYGB

LoadRunner + java脚本 第三章

标签:

原文地址:http://www.cnblogs.com/mayibanjiah/p/4821622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!