待测接口用java语言实现,且项目中调用该接口,请求报文直接送的对象,即需要用专门的jar包将数据转化为对象。

针对此类接口的LR压测脚本,可用Java Vuser协议实现,脚本中支持java语法。

代码样例如下:

/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/ import lrapi.lr;
import java.util.Date;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.isoftstone.rules.premium.service.IPremiumCalculation; public class Actions
{
static ApplicationContext context = new ClassPathXmlApplicationContext("remote-client-local.xml"); public int init() throws Throwable { return 0;
}//end of init public int action() throws Throwable { String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET type=\"REQUEST\" version=\"1.0\"><HEAD><REQUEST_TYPE>0355-01</REQUEST_TYPE><SYSNAME>V7核心</SYSNAME><SYSCODE>00</SYSCODE><USERCDE>134518100</USERCDE><DPTCDE>34</DPTCDE><TYPE>I</TYPE><DATA>A</DATA><SERVICE_NO>0101020202</SERVICE_NO><SERVICENAME>premCalc-ShangGaiHou</SERVICENAME><USERID>70000001</USERID><PASSWORD>123456</PASSWORD></HEAD><BODY><COVERAGE_LIST><COVERAGE><INSRNC_CDE>035801</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>0.00</BASE_PRM><BEF_PRM>216.91</BEF_PRM><STANDARD_PREMIUM>130.15</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>35</SERIAL_NO><N_SEATS></N_SEATS><INSURED>0.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035001</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>939.90</BASE_PRM><BEF_PRM>1446.00</BEF_PRM><STANDARD_PREMIUM>867.60</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>0</SERIAL_NO><N_SEATS></N_SEATS><INSURED>7590.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>939.9</RISK_PRM><RISK_PRM_FLAG>1</RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035802</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>0.00</BASE_PRM><BEF_PRM>459.15</BEF_PRM><STANDARD_PREMIUM>275.49</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>36</SERIAL_NO><N_SEATS></N_SEATS><INSURED>0.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035002</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>1989.65</BASE_PRM><BEF_PRM>3061.00</BEF_PRM><STANDARD_PREMIUM>1836.60</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>1</SERIAL_NO><N_SEATS></N_SEATS><INSURED>300000.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035803</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>0.00</BASE_PRM><BEF_PRM>10.80</BEF_PRM><STANDARD_PREMIUM>6.48</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>37</SERIAL_NO><N_SEATS></N_SEATS><INSURED>0.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035003</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>46.80</BASE_PRM><BEF_PRM>72.00</BEF_PRM><STANDARD_PREMIUM>43.20</STANDARD_PREMIUM><RATE>4.68</RATE><SERIAL_NO>3</SERIAL_NO><N_SEATS>1</N_SEATS><INSURED>10000.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035804</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>0.00</BASE_PRM><BEF_PRM>6.91</BEF_PRM><STANDARD_PREMIUM>4.15</STANDARD_PREMIUM><RATE>0.00</RATE><SERIAL_NO>38</SERIAL_NO><N_SEATS></N_SEATS><INSURED>0.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE><COVERAGE><INSRNC_CDE>035004</INSRNC_CDE><DEDUCTIBLE_CONVENTION></DEDUCTIBLE_CONVENTION><LIMIT_AMOUNT></LIMIT_AMOUNT><OPTIONAL_DI_DE></OPTIONAL_DI_DE><BASE_PRM>29.90</BASE_PRM><BEF_PRM>46.00</BEF_PRM><STANDARD_PREMIUM>27.60</STANDARD_PREMIUM><RATE>2.99</RATE><SERIAL_NO>4</SERIAL_NO><N_SEATS>1</N_SEATS><INSURED>10000.00</INSURED><REFERENCE_PREMIUNS></REFERENCE_PREMIUNS><CANCEL_MARK>0</CANCEL_MARK><RISK_PRM>0.00</RISK_PRM><RISK_PRM_FLAG></RISK_PRM_FLAG><MAINTENANCE_FACTOR></MAINTENANCE_FACTOR></COVERAGE></COVERAGE_LIST><BASE><PROD_NO>0355</PROD_NO><SALES_CHANNEL>19002</SALES_CHANNEL><ORIG_FLG>0</ORIG_FLG><DPT_CDE>34996603</DPT_CDE><SLS_CDE>134510951</SLS_CDE><SALEGRP_CDE>34996603005</SALEGRP_CDE><CMPNY_AGT_CDE></CMPNY_AGT_CDE><START_DATE>2016-12-11 00:00:00</START_DATE><END_DATE>2017-12-10 23:59:59</END_DATE><APP_DATE>2016-12-01</APP_DATE><SIGN_DATE>2016-12-01</SIGN_DATE><OPER_DATE>2016-12-01</OPER_DATE><SUMAMT>327590.00</SUMAMT><SUMPRM>3191.27</SUMPRM><PRM_CUR>01</PRM_CUR><RATIO>1.0</RATIO><OPR_TYP>0</OPR_TYP><PRNT_TYP>0</PRNT_TYP><CERTI_TYPE>124001</CERTI_TYPE><LASTPOLICYNO></LASTPOLICYNO><AGT_AGR_NO></AGT_AGR_NO><EXCHANGE_RATE>1.0</EXCHANGE_RATE><AMT_CUR>01</AMT_CUR><OPER_CDE>134518100</OPER_CDE><VHLGRP_FLG>0</VHLGRP_FLG><VHLGRP_PRO></VHLGRP_PRO><BSNS_NEW>191011</BSNS_NEW><CMM_PROP>0.38</CMM_PROP><CERTI_CODE></CERTI_CODE><SHORT_RATE>1</SHORT_RATE><REINSRC_FLG>0</REINSRC_FLG><DPT_CASCADE_CDE></DPT_CASCADE_CDE><COMPUTER_IP></COMPUTER_IP><USBKEY></USBKEY><LAST_YEAR_COMMERCIAL_WRECK_COUNT></LAST_YEAR_COMMERCIAL_WRECK_COUNT><INSURETYPE_FLAG></INSURETYPE_FLAG><CLAIM_AMOUNT></CLAIM_AMOUNT></BASE><VHL><BLD_YEAR></BLD_YEAR><BRND_CDE>KMD1282SDH</BRND_CDE><BRND_NME>凯马KMC5047D3XXY厢式运输车</BRND_NME><CAR_COLOUR></CAR_COLOUR><TFI_REF_CDE2></TFI_REF_CDE2><CONFIRM_CDE></CONFIRM_CDE><OWNER_NAME>王新祥</OWNER_NAME><ECDEMIC_VEHICLE_FLAG>0</ECDEMIC_VEHICLE_FLAG><ENGINE_NO>00938159</ENGINE_NO><DISPLACEMENT>2.16</DISPLACEMENT><USE_TYPE>345038013</USE_TYPE><VEHICLE_REGISTER_DATE>2009-12-14</VEHICLE_REGISTER_DATE><CAR_MARK>湾MM69531</CAR_MARK><VEHICLE_TYPE>345023002</VEHICLE_TYPE><PO_CATEGORY></PO_CATEGORY><VEHICLE_CATEGORY>345039006</VEHICLE_CATEGORY><VEHICLE_STYLE>345041055</VEHICLE_STYLE><QUERY_CDE>V0101ZSIC340016001480604351472</QUERY_CDE><RGN_CDE>002</RGN_CDE><USE_YEAR_CDE>345020004</USE_YEAR_CDE><USE_YEAR_NUM>6.992</USE_YEAR_NUM><VHL_BRAND></VHL_BRAND><RACK_NO>LWU2DM1C19KM08308</RACK_NO><VIN>LWU2DM1C19KM08308</VIN><RELATIONSHIP_WITH_VEHICLE>348001</RELATIONSHIP_WITH_VEHICLE><MADIN_CDE>34503601</MADIN_CDE><DEPRECIATION_COEFFICIENT>0.0090</DEPRECIATION_COEFFICIENT><MODELS_CONFIRMATION></MODELS_CONFIRMATION><BRAND_MODEL></BRAND_MODEL><EXTENDED_AREA_RADIUS></EXTENDED_AREA_RADIUS><PROPORTION_AGREEMENT></PROPORTION_AGREEMENT><TRAVEL_AREA_DESCRIPTION></TRAVEL_AREA_DESCRIPTION><VHL_GALSS>303011001</VHL_GALSS><INSURANCE_LAST_YEAR></INSURANCE_LAST_YEAR><LIABILITY_AMOUNT></LIABILITY_AMOUNT><LAST_YEAR_POLICY_NO></LAST_YEAR_POLICY_NO><ARE_TEAM>0</ARE_TEAM><LOAN_CAR_FLAG></LOAN_CAR_FLAG><TRANSFER_VEHICLE_LOGO>0</TRANSFER_VEHICLE_LOGO><FLEET_NO></FLEET_NO><NO_DAMAGE_YEARS></NO_DAMAGE_YEARS><LIMIT_LOAD_PERSON>2</LIMIT_LOAD_PERSON><LIMIT_LOAD>1.995</LIMIT_LOAD><NEWVHL_VAL>30000.00</NEWVHL_VAL><SUM_INSURED_TYPE></SUM_INSURED_TYPE><PACK></PACK><MODELS_ORIGINAL_PRICE></MODELS_ORIGINAL_PRICE><CHK_CDE>305005001</CHK_CDE><CHECK_MAN></CHECK_MAN><CHECK_TIME></CHECK_TIME><CHK_REC></CHK_REC><DEV_CDE></DEV_CDE><VEHICLE_MODEL></VEHICLE_MODEL><NEW_FLAG>1</NEW_FLAG><CERTIFICATE_DATE></CERTIFICATE_DATE><OWNER_TYPE>1</OWNER_TYPE><VHL_QUE_NO></VHL_QUE_NO><POWER>57</POWER><TRANSFER_DATE></TRANSFER_DATE><USE_YEAR_CDE1></USE_YEAR_CDE1><VEHICLE_CLASS_IFICATION></VEHICLE_CLASS_IFICATION></VHL><ADJUST><AVERAGE_MILE></AVERAGE_MILE><RGN_CDE /><GENDER /><AGE /><DRIVER_PERIOD /><CUSTOMER_LOYALTY /><NCD_PRIOR_YEAR>B13</NCD_PRIOR_YEAR><COEFFICIENT_SPECIAL_MATERIALS /><COVERAGE_NO /><EXPECTED_LOSS_RATIO /><SAFE_DRIVING /><AVERAGE_ANNUAL_MILEAGE /><DRIVER></DRIVER><AVERAGE_MILE_FACTOR></AVERAGE_MILE_FACTOR><MULTI_LINE_INSURANCE_FACTOR /><NO_COMPENSATI_COEFFICIENT>0.60</NO_COMPENSATI_COEFFICIENT><RISK_WARNING_FACTOR></RISK_WARNING_FACTOR><OVERALL_DISCOUNT>0.6</OVERALL_DISCOUNT><EE_LOSS_RATIO_FACTOR /><MANAGEMENT_LEVEL_FACTOR /><AVERAGE_ANNUAL_MILEAGE_FACTOR /><MORE_THAN_SAME_INSURING /><CAR_DAMAGE_MODEL_COEFFICIENT /><CLM_REC_VALUE /><CLM_REC_REASON /><KIND_ADJ_VALUE /><VHL_MDL_ADJ /><VHL_MDL_ADJ_UP /><VHL_MDL_ADJ_LOW /><PECC_REC_VALUE>1.0</PECC_REC_VALUE><PECC_REC_REASON></PECC_REC_REASON><MAG_ADJ /><MAG_ADJ_UPPER /><MAG_ADJ_LOW /><EXP_ADJ /><EXP_ADJ_UPPER /><EXP_ADJ_LOWER /><NO_CLAIMAD_JUST_REASON></NO_CLAIMAD_JUST_REASON><CONSULT_VALUE>7590.00</CONSULT_VALUE><PAYMENTRATE></PAYMENTRATE><CHA_FACTOR>0.85</CHA_FACTOR><UNDWRT_FACTOR>0.85</UNDWRT_FACTOR></ADJUST></BODY></PACKET>"; IPremiumCalculation service = (IPremiumCalculation) context.getBean("ilog"); lr.start_transaction("保费计算"); String response = service.invoke(request); lr.end_transaction("保费计算", lr.AUTO); System.out.println(response);
return 0;
}//end of action public int end() throws Throwable {
return 0;
}//end of end
}

remote-client-local.xml(放在脚本对应文件夹目录下)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="ilog"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl">
<value>http://IP address/ilog_webapp/remote/PremiumCalculation</value>
</property>
<property name="serviceInterface">
<value>com.isoftstone.rules.premium.service.IPremiumCalculation</value>
</property>
</bean> </beans>

Java Environment settings: classpath配置如下

LoadRunner系列之—-03 用Java Vuser协议编写接口测试脚本的更多相关文章

  1. loadrunner之Java Vuser协议脚本编写

    步骤:1.根据自己使用的lr版面选择jdk 1)LR11   1.6   32位 2)LR12   1.7   32位 2.安装好jdk,并搭建java环境变量,安装好java代码编写工具 3.在sr ...

  2. LoadRunner系列之—-04 录制基于https协议的脚本

    实际性能测试过程中,有些需录制脚本的页面或接口是基于https协议的,按原来方法录制脚本,录完了脚本是空的.为解决这个问题,第一步了解https协议的具体实现,这块网上资料很多,可参考页面下方参考资料 ...

  3. LR之Java Vuser

    虽然LR对C有较好的支持,但有时使用Java Vuser会更方便,以下描述通过LR来编写Java脚本以及调用jar包的基本步骤. 1.安装配置java环境  LR的java vuser脚本的执行依赖于 ...

  4. LoadRunner JAVA Vuser接口测试

    注:JDK只支持1.6 1.创建工程Test2.写个经典的HelloWorld类.3.Runas--->Java Application运行下4.将工程下的整个com包拷贝到loadrunner ...

  5. Loadrunner 11 中的Java Vuser

    Java vuser是自定义的java虚拟用户脚本,脚本中可以使用标准的java语言. 1.安装jdk 注意,lr11最高支持jdk1.6 2.配置环境变量 3.在lr中选择java vuser协议 ...

  6. JAVA VUser

    JAVA VUser 一.java虚拟用户协议 java虚拟用户脚本主要有Java Vuser.Corba-Java.RMI-Java.EJB等类型.这些类型的虚拟用户脚本均可以用java语言来手工编 ...

  7. LR使用Java User协议环境报错Please add the <JDK>\bin to the path and try again

    看标题报错信息就知道,这是java编译及运行环境配置问题,运行LR脚本时,LR代理找不到java的JDK环境,当然,可能有人会遇到说,我在cmd窗口javac 环境是没问题的呀,是的,这就要看你的jd ...

  8. 【原创】LoadRunner Java Vuser开发环境配置指南

    1 编写目的 本文主要介绍Java运行环境的配置,同时通过编写HelloWorld程序,讲解在LoadRunner下如何开发简单的Java Vuser脚本.关于Java语言的深入学习,大家可以参考其他 ...

  9. 【原创】LoadRunner Java Vuser脚本的配置和调试指南

    1 编写目的 本文介绍了Loadrunner多负载压力机的配置,并通过测试Java Vuser的数据库连接脚本对配置结果进行了验证,同时对配置过程中遇到的问题和解决的过程进行了记录,关于Java数据库 ...

随机推荐

  1. 解决mysql - 1577 问题

    背景:通过navicat连接mysql使用events时报如下错误 登录mysql查询event mysql> use zhk4; Database changed mysql> show ...

  2. Verdi:内存不足

    如果进行Verdi compile时,出现memory资源不够用.有可能case中出现了问题(或许发生了死循环,造成内存严重占用),此时尽量瘦身TC_FILE_LIST文件,缩小问题case的范围.

  3. java线程总结--synchronized关键字,原理以及相关的锁

    在多线程编程中,synchronized关键字非常常见,当我们需要进行“同步”操作时,我们很多时候需要该该关键字对代码块或者方法进行锁定.被synchronized锁定的代码块,只能同时有一条线程访问 ...

  4. 【BZOJ 1084】 [SCOI2005]最大子矩阵(DP)

    题链 http://www.lydsy.com/JudgeOnline/problem.php?id=1084 Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩 ...

  5. POJ 1414 Life Line(搜索)

    题意: 给定一块正三角形棋盘,然后给定一些棋子和空位,棋子序号为a(1<=a<=9),group的定义是相邻序号一样的棋子. 然后到C(1<=N<=9)棋手在空位放上自己序号C ...

  6. 【转】SQL Server 2008 新数据类型

    概览: 新日期和时间数据类型 代表在层次结构中的位置 用于处理空间数据的两种模型 在全球经济环境下开展业务这一趋势越来越要求各公司使用新型的数据.应用程序以及复杂的计算.SQL Server 2008 ...

  7. window查看哪些端口被占用命令

    管理员方式运行cmd netstat -n

  8. 理工个人积分赛最后一场(FZU)G - 五子棋,坑爹的大水题~~

    Problem 1490 五子棋 Time Limit: 1000 mSec Memory Limit : 32768 KB  Problem Description 五子棋是起源于中国古代的传统黑白 ...

  9. [USACO10FEB]慢下来Slowing down

    线段树  树的dfs序 来自   洛谷 P1982   的翻译 by  GeneralLiu 来自 jzyz 的翻译 %mzx 线段树  dfs序 数据结构的应用 “数据结构 是先有需求 再有应用” ...

  10. PHP复制和移动目录

    <?php //重命名一个文件或目录 rename("phpmyadmin", "phpadmin");//重命名成phpadmin /* * $dirs ...