LoadRunner ERROR: java.lang.NumberFormatException

  Loadrunner中使用lr_xml_get_values()获取服务端返回的字符串LcsId,LcsId为double,需要将该值转换为 int 后传入下一次请求中。 

  报错如下:Error is : Exception Occurred while invoking WriteObject method; Debugging information: cause-exception : java.lang.NumberFormatException.

  解决方法:

  需要对flex_amf_call()的Response进行数据提取,提取的数据为double,但是submit.c中需要int,于是牵扯数据类型转换。

  本以为只需要使用一个整型变量transferedLcsId接收,然后在submit.c中将<string>transferedLcsId</string><int>***</int>的“***”替换为“transferedLcsId”,就好了,但是始终报错,查看扩展日志后发现,是格式转换的问题;

  最终添加lr_save_int()将transferedLcsId保存为int,得以解决,如下。

错误代码:

int  transferedLcsId;    //存放在globals.h文件中

flex_amf_call(

 "AMF3_call_16",

 "ResponseParameter=response",

);

lr_xml_get_values("XML={response}",

 "Query=//string[contains(text(),'id')]/following::double",

 "ValueParam=id",

 LAST

);

transferedLcsId = atoi(lr_eval_string ("{id}"));

 

解决后代码:

int  transferedLcsId;    //存放在globals.h文件中

flex_amf_call(

   "AMF3_call_16",

 "ResponseParameter=response",

);

lr_xml_get_values("XML={response}",

 "Query=//string[contains(text(),'id')]/following::double",

 "ValueParam=id",

 LAST

);

transferedLcsId = atoi(lr_eval_string ("{id}"));

lr_save_int (transferedLcsId,"transferedLcsId");  //重要的保存

flex_amf_call(

 "AMF3_call_17",

 "<string>transferedLcsId</string><int>transferedLcsId</int>"

);

flex_amf_call(

 "AMF3_call_17",

 "<string>transferedLcsId</string><int> { transferedLcsId } </int>"

);

  总结:虽然transferedLcsId是整型变量,但是需要使用lr_save_int函数将该变量用loadrunner可以识别的参数化方式保存起来,即需要从C语言格式转换为LR可以识别的格式,再应用到录制的脚本中。

  lr_save_int在man手册中的功能解释:Saves an integer to a parameter.类似的还有:

posted @ 2016-11-07 15:11  天使未必在场  阅读(240)  评论(0编辑  收藏  举报