loadrunnerjava脚本saf
1.导入相对应的jar包
2.使用java反编译工具反编译jar包,了解其中的业务流程,选择需要的service以及方法。以下以productWrapService服务为例。
3.在saf框架的配置文件中注册:
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="/schema/beans"xmlns:xsi="/2001/XMLSchema-instance"xmlns:saf="/schema/saf"xmlns:dubbo="/schema/dubbo"xsi:schemaLocation="/schema/beans/schema/beans/spring-beans-2.5.xsd/schema/saf/schema/saf/saf.xsd/schema/dubbo/schema/dubbo/dubbo.xsd"default-lazy-init="true"><saf:registryaddress="jdZooKeeper://192.168.12.159:2181"/><saf:referenceid="productWrapService"interface="xx.xx.xx.pbim.pbia.dubbo.service.ProductWrapService"group="xxxx"version="1.0"timeout="30000"/><saf:referenceid="bookVideoService"interface="xx.xx.xx.pbim.pbia.dubbo.service.BookVideoService"group="xxxx"version="1.0"timeout="30000"/><saf:referenceid="attributeService"interface="xx.xx.xx.pbim.pbia.dubbo.service.AttributeService"group="xxxx"version="1.0"timeout="30000"/></beans>
4.编写loadrunner脚本:
Java代码 /**LoadRunnerJavascript.(Build:_build_number_)**ScriptDescription:**/importlrapi.lr;importcom.xxx.catagory.pbim.pbia.dubbo.service.ProductWrapService;importcom.xxx.catagory.pbim.pbia.dubbo.model.ProductSort;importjava.util.*;importjava.lang.*;importorg.springframework.context.support.ClassPathXmlApplicationContext;publicclassActions{ProductWrapServicer=null;publicintinit()throwsThrowable{inti=0;ClassPathXmlApplicationContextcontext=newClassPathXmlApplicationContext("applicationContext-dubbo.xml");//读环境配置XML,并注册SAF和redis认证r=(ProductWrapService)context.getBean("productWrapService",ProductWrapService.class);return0;}//endofinitpublicintaction()throwsThrowable{IntegerskuIdInteger;Set<Integer>cids=newHashSet<Integer>();Stringstr=lr.eval_string("<P_sortid>");skuIdInteger=Integer.valueOf(str);cids.add(skuIdInteger);List<ProductSort>retList=newArrayList<ProductSort>();ProductSortps=newProductSort();lr.start_transaction("productWrapService_queryProductSort");try{retList=r.queryProductSort(cids);for(Iteratori$=retList.iterator();i$.hasNext();){ps=(ProductSort)i$.next();lr.output_message("+++++++++"+ps.getName());}//lr.output_message("++++++++"+retList);if(retList!=null){lr.end_transaction("productWrapService_queryProductSort",lr.PASS);}else{lr.end_transaction("productWrapService_queryProductSort",lr.FAIL);}}catch(Exceptione){e.printStackTrace();}return0;}//endofactionpublicintend()throwsThrowable{return0;}//endofend}
如果觉得《loadrunner之java协议脚本编写》对你有帮助,请点赞、收藏,并留下你的观点哦!