当前位置:首页 > 开发 > IT生活 > 正文

loadrunner xml脚本和json脚本

发表于: 2015-05-15   作者:Alice南京   来源:转载   浏览:
摘要: 今天简单的和开发沟通 报文分为xml和json xml有我平时录制的时候已一个个参数去提交的a,也有以报文体整个去提交的b。 json以打括号去提交的c。 a.xml以参数提交 b.xml以报文体提交 开发提供报文 <MbfService> <input1> <MbfHeader> <ServiceCode>Clo
今天简单的和开发沟通
报文分为xml和json
xml有我平时录制的时候已一个个参数去提交的a,也有以报文体整个去提交的b。
json以打括号去提交的c。

a.xml以参数提交

b.xml以报文体提交
开发提供报文
<MbfService>
<input1>
<MbfHeader>
<ServiceCode>CloudProviderCardOrderMgmt</ServiceCode>
<Operation>syncCPOrderSummaryInfo</Operation>
<AppCode>OMS</AppCode>
<UId>d24de41c71e744a085f682123f8972999638ddc0e74d4cc5</UId>
<AuthId>OMS;NULL</AuthId>
</MbfHeader>
<MbfBody>
<salesOrderItems>
<salesOrderMain>
<opType>A</opType>
<orderId>123456000001</orderId>
<omsCreateTime>20150509144225</omsCreateTime>
<operatMum>13091704</operatMum>
<orderItemId>12345600000101</orderItemId>
<preOrderItemId/>
<distChannel>10</distChannel>
<saleOrg>1001</saleOrg>
<storeCode>7610</storeCode>
<cmmdtyCode>509990080</cmmdtyCode>
<price>100.00</price>
<saleQty>1.000</saleQty>
<totalAmount>100.00</totalAmount>
<customerName>测试用户</customerName>
<memberCardNo>025051600001</memberCardNo>
</salesOrderMain>
<extendedInformation>
<activeType></activeType>
<arrearageType></arrearageType>
<rebateType></rebateType>
<documenNum></documenNum>
<documenType></documenType>
<soaNum/>
<remark/>
</extendedInformation>
<salesOrderPayItem>
<payCode>1001</payCode>
<payAmount>100.00</payAmount>
<payTime>20150509144225</payTime>
</salesOrderPayItem>
</salesOrderItems>
</MbfBody>
</input1>
</MbfService>



loadrunner脚本
int respCode0;
    lr_start_transaction("OMS Order Information Synchronization"); 

	web_reg_save_param("respCode",
		"LB=<respCode>",
		"RB=</respCode>",
		"NotFound=ERROR",
		"Search=All",
		LAST);

    [color=blue]web_custom_request[/color]("esbHttpService",  
        "URL=http://*.*.*.*:3/ManagementFrontEndWeb/esbHttpService", 
        "Method=POST",  
        "Mode=HTTP",  
      [color=blue]  "EncType=text/xml; charset=GB2312",  
        "Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"  [/color]
        "<MbfService>[color=red]" [/color]
        "<input1>[color=red]"[/color]
        "<MbfHeader>[color=red]"  [/color]     
        "<ServiceCode>CloudProviderCardOrderMgmt</ServiceCode>"
        "<Operation>syncCPOrderSummaryInfo</Operation>"
        "<AppCode>OMS</AppCode>"
        "<UId>d24de41c71e744a085f682123f8972999638ddc0e74d4cc5</UId>"
        "<AuthId>OMS;NULL</AuthId>"
        "</MbfHeader>" 
        "<MbfBody>"
        "<salesOrderItems>"
        "<salesOrderMain>"
        "<opType>A</opType>"
        "<orderId>123456000001</orderId>"
        "<omsCreateTime>20150509144225</omsCreateTime>"
        "<operatMum>13091704</operatMum>"
        "<orderItemId>12345600000101</orderItemId>"
        "<preOrderItemId/>"
        "<distChannel>10</distChannel>"
        "<saleOrg>1001</saleOrg>"
        "<storeCode>7610</storeCode>"
        "<cmmdtyCode>509990080</cmmdtyCode>"
        "<price>100.00</price>"
        "<saleQty>1.000</saleQty>"
        "<totalAmount>100.00</totalAmount>"
        "<customerName>测试用户</customerName>"
        "<memberCardNo>025051600001</memberCardNo>"
        "</salesOrderMain>"
        "<extendedInformation>"
        "<activeType></activeType>"
        "<arrearageType></arrearageType>"
        "<rebateType></rebateType>"
        "<documenNum></documenNum>"
        "<documenType></documenType>"
        "<soaNum/>"
        "<remark/>"
        "</extendedInformation>"
        "<salesOrderPayItem>"
        "<payCode>1001</payCode>"
        "<payAmount>100.00</payAmount>"
        "<payTime>20150509144225</payTime>"
        [color=red]"[/color]</salesOrderPayItem>"
        [color=red]"[/color]</salesOrderItems>"
        [color=red]"[/color]</MbfBody>"  
        [color=red]"[/color]</input1>"  
        [color=red]"[/color]</MbfService>",
		LAST); 
	 respCode0=strcmp(lr_eval_string("respCode"),lr_eval_string("00"));
	 
	 if(respCode0==0)	
		 { 
       
		 lr_output_message("PASS-----respCode:%s",lr_eval_string("{respCode}"));
		 lr_output_message("PASS-----respCode0:%s",lr_eval_string("respCode0"));
	     lr_end_transaction("OMS Order Information Synchronization",LR_PASS); 
	    }
	   else
      	{
		 lr_output_message("FAIL----respCode:%s",lr_eval_string("{respCode}"));
         lr_end_transaction("OMS Order Information Synchronization",LR_FAIL); 
	   };

         return 0;  

c.以表单提交,使用用json格式
  JSON简单说就是javascript中的对象和数组。
  JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它的规则非常简单并且是有趣的:
1) 并列的数据之间用逗号(“,”)分隔。
2) 映射用冒号(“:”)表示。
3) 并列数据的集合(数组)用方括号("[]")表示。
4) 映射的集合(对象)用大括号(“{}”)表示。
按照这个规则可以作以下理解:
1.数组用“[]”创建,对象用“{}”创建,并且使用Json基本都是用[]或者{}创建的数组或对象,否则一个普通的字符串是没有意义的;
2.无论是数组还是对象,之间的元素都用“,”隔开;
3.对象内部,(属性的)名称和值用“:”隔开,并且必须要用“:”隔开,不可单独存在属性名或者值;
4.对象和数组可以互相嵌套,即数组中的一个元素可以是一个对象也可以是一个数组,同理对象中的一个属性的值可以是一个对象也可以是一个数组。
举例
data={"authInfo":{"orderInfo":"account_no=0000000001114011378&total_fee=100","orderType":"01"},"deviceInfo":{"deviceId":"865179020041956","deviceName":"TCLP728M","deviceSysVersion":"19","serialNumber":"SSOBFACQS4GUSSBE","wlanMacAddress":"d8:e5:6d:b6:97:a1"},"platformType":"02","platformInfo":{"appId":"120001","sdkVersion":"2"},"clientKey":"k78Rn23s"}"

  了解了json格式,下面来说表单提交:
http://sdkspre.*.com/sdkservice/showCashier/showCashier.do?data={"authInfo":{"orderInfo":"account_no=0000000001114011378&total_fee=100","orderType":"01"},"deviceInfo":{"deviceId":"865179020041956","deviceName":"TCLP728M","deviceSysVersion":"19","serialNumber":"SSOBFACQS4GUSSBE","wlanMacAddress":"d8:e5:6d:b6:97:a1"},"platformType":"02","platformInfo":{"appId":"120001","sdkVersion":"2"},"clientKey":"k78Rn23s"}"  	[MsgId: MMSG-26548]

表单提交需要放在ITEMDATA内
脚本如下:
Action()
{   
	lr_start_transaction("show");

	web_reg_find("Fail=NotFound",
		"Search=All",
		"Text=\"success\":true,",
		LAST);

	web_submit_data("showCashier.do", 
		"Action=http://sdkspre.*.com/sdkservice/showCashier/showCashier.do",
		"Method=POST", 
		"TargetFrame=", 
		"RecContentType=text/html", 
		"Referer=", 
		"Snapshot=t3.inf", 
		"Mode=HTML", 
		 ITEMDATA, 
	     "Name=data", "Value={\"authInfo\":{\"orderInfo\":\"account_no=0000000001114011378&total_fee=100\",\"orderType\":\"01\"},\"deviceInfo\":{\"deviceId\":\"865179020041956\",\"deviceName\":\"TCLP728M\",\"deviceSysVersion\":\"19\",\"serialNumber\":\"SSOBFACQS4GUSSBE\",\"wlanMacAddress\":\"d8:e5:6d:b6:97:a1\"},\"platformType\":\"02\",\"platformInfo\":{\"appId\":\"120001\",\"sdkVersion\":\"2\"},\"clientKey\":\"k78Rn23s\"}", ENDITEM, 
		 LAST);

	lr_end_transaction("show", LR_AUTO);

	return 0;
}


下面在补充下:
开始将data放在url地址中一起提交,开发在日志中只能接收到data的第一个参数-encryptStr:{"authInfo":{"orderInfo":"account_no=0000000001114011378
所以需要放在itemdata中通过表单提交。
使用get发现也不ok,因为我们传的字段里面有特殊字符 如果用get需要url encode 不然就传不过来,但是用post 系统会自动编码,所以选择post。

loadrunner xml脚本和json脚本

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

推荐文章
编辑推荐
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号