LoadRunner + java脚本 第三章
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