QTP成长园地
LR 从XML文件读取数据(转载)
上一篇 /
下一篇 2009-05-21 15:47:19
/ 个人分类:LoadRunner
1.配置文件"c:\\hfeitest.xml"
<users>
<user>
<name>abc0015admin0</name>
<productId>B001261</productId>
<unitId>A0000Q1</unitId>
<customerId>B00141</customerId>
<supplierId>B001262</supplierId>
<storeId>B001162</storeId>
<accountId>B001162</accountId>
<employeeId>A00010</employeeId>
<departmentId>A00010</departmentId>
<paymentMethodId></paymentMethodId>
</user>
</users>
2.代码
#include "as_web.h"
char *productId;//产品
char *unitId;//计量单位
char *customerId;//客户
char *supplierId;//供应商
char *storeId;//仓库
char *accountId;//帐号
char *employeeId;//职员
char *departmentId;//部门
char *paymentMethodId;//付款方式
//作者:黄飞
//日期:20080216
//功能:根据传入用户参数,初始化产品等变量配置,达到动态获取参数的目的
initData(char userId)
{
char *filename = "c:\\hfeitest.xml";
char *content;
char buffer[1000];
long file_stream;
if ((file_stream = fopen(filename, "r" )) == NULL) {
lr_output_message("Unable to create %s", filename);
return -1;
}
lr_save_string(lr_eval_string(""),"XML_Input_Param");
while(!feof(file_stream))
{
fread(buffer, sizeof(char), 999, file_stream);
buffer[len] = '\0';
lr_save_string(buffer,"content");
lr_save_string(lr_eval_string("{XML_Input_Param}{content}"),"XML_Input_Param");
}
fclose(file_stream);
lr_output_message(lr_eval_string("{XML_Input_Param}"));
lr_output_message(lr_eval_string("{userId}"));
lr_xml_get_values("XML={XML_Input_Param}",
"ValueParam=OutputParam",
"Query=/users/user[name=\"{userId}\"]/productId",
LAST);
lr_save_string(lr_eval_string("{OutputParam}"), "productId");
lr_output_message(lr_eval_string("UserNamaID={userId} and Query productId = {productId}"));
}
vuser_init()
{
char userId;
lr_save_string(lr_eval_string("{username}"), "userId");
initData(userId);
...
}
收藏
举报
TAG: