LoadRunner的xml协议使用

转自:http://lht821008.blog.163.com/blog/static/4164786201141134535464/

思考曾经做过的一个黄金交易系统,里面针对后端进行报文发送,报文均是采用的xml格式,只不过传输和接受前后需要进行加解密,现在想来如果不是由于加解密包采用的是java,那我们完全可以采用LR的原生态C函数和XML协议函数做到更为优雅的测试脚本,利用LR的xml函数对整个xml报文实现动态封转。
函数:lr_xml_get_values
Action()
{
char *xml_input=
"<love>"
"<name_man>LHT</name_man>"
"<name_women>PHOEBE</name_women>"
"</love>";

lr_save_string(xml_input,"xml_param");

lr_xml_get_values("XML={xml_param}",
"ValueParam=OutputParam1",
"Query=/love/name_man",
LAST);

lr_xml_get_values("XML={xml_param}",
"ValueParam=OutputParam2",
"Query=/love/name_women",
LAST);

lr_message("husband is:%s",lr_eval_string("{OutputParam1}"));

lr_message("wife is:%s",lr_eval_string("{OutputParam2}"));

return 0;
}
//output

husband is:LHT
wife is:PHOEBE


函数lr_xml_set_values

Action1() {

char * xml_input =

"<acme_org>"

" <accounts_dept>"

"<employee>"

" <name>John Smith</name>"

"<cubicle>227</cubicle>"

"<extension>2145</extension>"

"</employee>"

"</accounts_dept>"

"<engineering_dept>"

"<employee>"

"<name>Sue Jones</name>"

"<extension>2375</extension>"

"</employee>"

"</engineering_dept>"

"</acme_org>";


int i,NumOfValues;

char buf[64];


lr_save_string(xml_input,"XML_Input_Param"); // Save input as parameter

lr_save_string("lht","ExtensionParam_1");

lr_save_string("phoebe","ExtensionParam_2");

lr_xml_set_values("XML={XML_Input_Param}",

"ResultParam=NewXmlParam",

"ValueParam=ExtensionParam",

"SelectAll=yes",

"Query=//extension",

LAST);


NumOfValues= lr_xml_get_values("XML={NewXmlParam}",

"ValueParam=OutputParam",LAST);


for ( i = 0; i < NumOfValues; i++) { /* Print the multiple values of MultiParam */

sprintf (buf,"Retrieved value %d : {OutputParam_%d}",i+1,i+1);

lr_output_message(lr_eval_string(buf));

}


lr_message("new xml is:%s",lr_eval_string("{NewXmlParam}"));

return 0;

}
//output:

Virtual User Script started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(11): "lr_xml_get_values" succeeded,1 match processed
Action.c(16): "lr_xml_get_values" succeeded,1 match processed
husband is:LHT
wife is:PHOEBE
Ending action Action.
Starting action Action1.
Action1.c(47): "lr_xml_set_values" succeeded,2 matches processed
Action1.c(60): "lr_xml_get_values" succeeded,2 matches processed
Action1.c(73): Retrieved value 1 : lht
Action1.c(73): Retrieved value 2 : phoebe
new xml is:<acme_org> <accounts_dept><employee> <name>John Smith</name><cubicle>227</cubicle><extension>lht</extension></employee></accounts_dept><engineering_dept><employee><name>Sue Jones</name><extension>phoebe</extension></employee></engineering_dept></acme_org> Ending action Action1. Ending iteration 1. Ending Vuser... Starting action vuser_end. Ending action vuser_end. Vuser Terminated.

相关文章

引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满足人的生产生活需要而产生的。具体...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
http://blog.jobbole.com/79252/ 引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满...
(点击上方公众号,可快速关注) 公众号:smart_android 作者:耿广龙|loonggg 点击“阅读原文”,可查看...
一、xml与xslt 相信所有人对xml都不陌生,其被广泛的应用于数据数据传输、保存与序列化中,是一种极为强...