抓包测试工具与LoadRunner结合实践

本文介绍了如何结合Wireshark和Fiddler抓包工具,与LoadRunner一起进行测试。通过Fiddler抓取HTTP流量,分析请求头和JSON数据,辅助手动编写LoadRunner脚本。在遇到LR录制问题时,可以通过调整抓包数据的JSON格式来适应LR,如替换特殊字符。同时,文中提供了调试JSON格式的几种方法,并提到了转换.saz文件为Vugen Script的简便方法。

两种抓包工具Wireshark和Fiddler

Fidder专门针对HTTP流进行抓包

Wireshark可以抓到各种协议的通讯包。

以USKSA项目为例子,我们可以通过Fiddler工具来抓包,效果如下


 

录制后,通过分析Header 和Request json,可以达到手写loadrunner脚本的效果,因为网速的状况有时候导致LR录制不到,如此用抓包工具分析手写script不用拘束于用Loadrunner工具来录制,

 

 


 

 

这些request脚本通过比对,发现跟Loadrunner录制的json格式上基本一样,但是需要调整几个地方

所以如下几个步骤

1,将Request的json数据拷贝到txt文件中,用NodePad++ 工具打开(在此推荐NodePad++工具)通过添加jsonView插件可以调整json格式)


 

2. 将 单斜杠 替换为 双斜杠  (\    —>   \\)

3.将 单引号 替换为 斜杠单引号  ("   —> \")

这样的json格式就符合LR提交的json格式了

如:

"Body={

\"evalItem\":{\"performId\":\"{PerformId}\",\"versionId\":\"USK.MST.2015.13\",\"itemId\":\"DEV0000081\",\"parentId\":\"FU00000015\",\"dataType\":\"Standard\",\"dataLevel\":\"3\",\"answerType\":\"YES_NO\",\"pointValue\":1,\"deductPoint\":0,\"earnPoint\":0,\"priority\":0,\"optional\":false,\"ancestorIds\":\"\\\"SC00000003\\\",\\\"FU00000015\\\"\",\"value0\":\"Y\",\"value1\":\"\",\"value2\":\"\",\"value3\":\"\",\"value4\":0,\"value5\":\"\",\"value6\":\"\",\"value7\":\"\",\"value8\":\"\",\"value9\":\"\",\"value10\":\"\",\"bizLevel\":1,\"bizLevelUpgraded\":1,\"bizLevelMax\":2,\"rptPlatform\":\"\",\"bmu\":\"\",\"concept\":\"\",\"validationType\":\"\",\"validationRule\":\"\",\"valueList\":\"\",\"videoLink\":\"\",\"fsc\":0,\"fsiCode\":\"CL101\",\"displayId\":\"\",\"photo\":true,\"maint\":false,\"detailRequired\":false,\"qualityGuide\":\"RFIL000163\",\"summaryCat\":\"SMCT000003\",\"desc0\":\"Exterior building and all exterior structures are clean.\",\"desc1\":\"\\u25cf No soil on exterior building or other structures (such as fences, retaining walls and decking), windows (sills, frames, seals), doors (frames, handles, thresholds, locks/keypads, closures, hardware), lights (fixtures, functioning), roof (tile, gutters, drains/downspouts), awnings or any element of the building.  \\n\\u25cf There should be no dirt buildup, graffiti, mildew, algae, smear marks, streaks or fingerprints.  \\n\\nWHY is this important?\\n\\u2022 Poor appearance and condition of the restaurant exterior is shown to have a significant impact on a Guest's decision on whether or not to visit a restaurant.\\n\\u2022 The best way to invite Guests into the restaurant is to impress them with a clean and well-maintained exterior.\",\"desc2\":\"\\u25cf One of anything listed (webs, graffiti, buildup dirt, etc.) is an issue.\\n\\u25cf Allow 2 issues before scoring.\",\"desc3\":\"Allow 2 issues.\\nL1 if 3-4 issues.\\nL2 if >4 issues.  \",\"selectionList\":null,\"reoccurring\":2,\"occurredInMR\":true,\"qualityGuides\":[{\"itemId\":\"RFIL000163\",\"desc0\":\"Guest Touch Points job aid\",\"desc1\":\"/ROCC.FILE.2014.01/RFIL000163/RFIL000163_en_US.pdf\",\"displayOrder\":null,\"detailRequired\":false,\"rawValue\":null,\"label\":null,\"path\":null,\"uri\":null}]},\"operationType\":\"answer\"

}",
LAST);

 

几种调试json格式的方法:

 


 

将URL换成本地URL并且手写Script

做下实验,看看抓包的json经过调试能否正常的通过Loadrunner执行

Action()
{


	
web_set_sockets_option("SSL_VERSION", "TLS");
	
    web_url("usksa.nextxnow.com",
     "URL=http://10.0.0.95:8030/USKSA/ ",
     "Resource=0",
     "RecContentType=text/html",
     "Mode=HTML",
     LAST );
     
     
  	web_submit_data("j_spring_security_check",
		"Action=http://10.0.0.95:8030/USKSA/j_spring_security_check",
		"Method=POST",
		"Referer=http://10.0.0.95:8030/USKSA/",
		"Mode=HTTP",
		ITEMDATA,
		"Name=j_username", "Value=demo.web", ENDITEM,
		"Name=j_password", "Value=china8620", ENDITEM,
		"Name=languageCode", "Value=en_US", ENDITEM,
	    "Name=webType", "Value=ROCC", ENDITEM, 
		EXTRARES,
		LAST);
		
			web_custom_request("userAccess", 
		"URL=http://10.0.0.95:8030/USKSA/controller/security/userAccess", 
		"Method=POST", 
		"Resource=0", 
		"RecContentType=application/json", 
		"Referer=http://10.0.0.95:8030/USKSA/eval/index.html", 
		 
		"Mode=HTTP", 
		"EncType=", 
		LAST);
       
    
     web_reg_save_param("PerformId",
		"LB=\"performId\":\"",
		"RB=\",",
		"Search=Body",
		LAST);
		
		web_custom_request("create",
		"URL=http://10.0.0.95:8030/USKSA/controller/eval/create",
		"Method=POST",
		"Resource=0",
		"RecContentType=application/json",
		"Referer=http://10.0.0.95:8030/USKSA/web/index.html",
		"Snapshot=t10.inf",
		"Mode=HTTP",
		"EncType=application/json; charset=UTF-8",
		"Body={\"storeInfo\":{\"bmu\":\"USK\",\"concept\":\"Kx\",\"account\":\"\",\"brand\":\"KFC\",\"accountNumber\":\"0000034\",\"ownerFirst\":null,\"ownerLast\":null,\"address\":\"28054-2 CR 4 West\",\"city\":\"Elkhart\",\"state\":\"IN\",\"zip\":\"46514\",\"phone\":\"5749701522\",\"type\":\"License\",\"status\":\"O\",\"acFirst\":null,\"acLast\":null,\"morFirst\":null,\"morLast\":null,\"specNtId\":null,\"cntryCode\":null,\"closeDate\":null,\"reopenDate\":null,\"importStatus\":null,\"storeName\":null,\"accountName\":\"\",\"owner\":\"Paul Kelly\",\"keyOp\":\"\",\"ac\":\"\",\"country\":\"\",\"fax\":\"\",\"x1key1first\":null,\"x2key1last\":null,\"acEmail\":null,\"morEmail\":null,\"ownerEmail\":null,\"regnEmail\":null,\"fbcEmail\":null,\"rgmEmail\":null,\"generalManage\":null},\"timezone\":0,\"rsv4\":\"2015-12-18 17:21:51\",\"rsv5\":\"ROCC\",\"selectedConcept\":\"Kx\",\"mic\":\"xx\",\"micPosition\":\"RGM\",\"userId\":\"demo.web\",\"userSeqId\":1332,\"firstName\":\"Demo\",\"lastName\":\"Web\",\"visitType\":\"Test\",\"beginTime\":\"5:21 PM\",\"endTime\":\"\",\"dayPart\":\"Dinner 5-8\",\"rating\":\"\",\"ratingValue\":\"\",\"lockDate\":\"\",\"languageCode\":\"en_US\",\"rgmName\":\"xx\",\"previousPlan\":\"\",\"generalComments\":\"\",\"performType\":\"CER\"}",
		LAST);
		
lr_output_message("-------PerformId is----------- : %s", lr_eval_string("{PerformId}"));
	web_custom_request("update_DEV0000081", 
		"URL=http://10.0.0.95:8030/USKSA/controller/eval/update", 
		"Method=POST", 
		"Resource=0", 
		"RecContentType=application/json", 
		"Referer=http://10.0.0.95:8030/USKSA/web/index.html", 
		"Snapshot=t17.inf", 
		"Mode=HTTP", 
		"EncType=application/json; charset=UTF-8", 
		"Body={\"evalItem\":{\"performId\":\"{PerformId}\",\"versionId\":\"USK.MST.2015.13\",\"itemId\":\"DEV0000081\",\"parentId\":\"FU00000015\",\"dataType\":\"Standard\",\"dataLevel\":\"3\",\"answerType\":\"YES_NO\",\"pointValue\":1,\"deductPoint\":0,\"earnPoint\":0,\"priority\":0,\"optional\":false,\"ancestorIds\":\"\\\"SC00000003\\\",\\\"FU00000015\\\"\",\"value0\":\"Y\",\"value1\":\"\",\"value2\":\"\",\"value3\":\"\",\"value4\":0,\"value5\":\"\",\"value6\":\"\",\"value7\":\"\",\"value8\":\"\",\"value9\":\"\",\"value10\":\"\",\"bizLevel\":1,\"bizLevelUpgraded\":1,\"bizLevelMax\":2,\"rptPlatform\":\"\",\"bmu\":\"\",\"concept\":\"\",\"validationType\":\"\",\"validationRule\":\"\",\"valueList\":\"\",\"videoLink\":\"\",\"fsc\":0,\"fsiCode\":\"CL101\",\"displayId\":\"\",\"photo\":true,\"maint\":false,\"detailRequired\":false,\"qualityGuide\":\"RFIL000163\",\"summaryCat\":\"SMCT000003\",\"desc0\":\"Exterior building and all exterior structures are clean.\",\"desc1\":\"\\u25cf No soil on exterior building or other structures (such as fences, retaining walls and decking), windows (sills, frames, seals), doors (frames, handles, thresholds, locks/keypads, closures, hardware), lights (fixtures, functioning), roof (tile, gutters, drains/downspouts), awnings or any element of the building.  \\n\\u25cf There should be no dirt buildup, graffiti, mildew, algae, smear marks, streaks or fingerprints.  \\n\\nWHY is this important?\\n\\u2022 Poor appearance and condition of the restaurant exterior is shown to have a significant impact on a Guest's decision on whether or not to visit a restaurant.\\n\\u2022 The best way to invite Guests into the restaurant is to impress them with a clean and well-maintained exterior.\",\"desc2\":\"\\u25cf One of anything listed (webs, graffiti, buildup dirt, etc.) is an issue.\\n\\u25cf Allow 2 issues before scoring.\",\"desc3\":\"Allow 2 issues.\\nL1 if 3-4 issues.\\nL2 if >4 issues.  \",\"selectionList\":null,\"reoccurring\":2,\"occurredInMR\":true,\"qualityGuides\":[{\"itemId\":\"RFIL000163\",\"desc0\":\"Guest Touch Points job aid\",\"desc1\":\"/ROCC.FILE.2014.01/RFIL000163/RFIL000163_en_US.pdf\",\"displayOrder\":null,\"detailRequired\":false,\"rawValue\":null,\"label\":null,\"path\":null,\"uri\":null}]},\"operationType\":\"answer\"}", 
		LAST);

	
	return 0;
}


执行后 如下:



以后可以通过设置网络,来抓取IOS平台app的http包从而手写script进行并发。

方式二:(更简单直白的方式)

直接右键将.saz格式的抓包文件转化成 Vugen Script

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值