天天看点

LoadRunner中写文件的案例

  策略:

  1、loadruner中是不支持file数据类型的,所以用int或者long来声明一个文件;

  3、fopen()方法。可参考:《loadrunner下如何进行文件的操作》

  fopen(filename,"a")) :文件存在,就覆盖写,不存在会先创建。为了不让它每次覆盖,我在fprintf()中使用了“%s\n”,每次都换行追加;

  有人试过fopen(filename,"a+")) ,这样写的效果是一样的。

  实现:

action{

long file_stream;

char *filename = "c:\\001.txt";

soap_request(此段省略,即webservice协议的两种生成脚本方式);

// 将response出力

lr_message(lr_eval_string("response is: \n {response}"));  // 此处response是无须定义的,原因自己理解

// 取所需的依赖字段,关键函数lr_xml_get_values

lr_xml_get_values("xml = {response}",

"valueparam = valueparam ",

"query = xxx",

last);  // 此函数自行理解使用方法

// 本文重点 写文件

if((file_stream = fopen(filename,"a")) == null){

lr_error_message("cannot open %s",filename);

return -1;

}

fprintf(file_stream,"%s\n",lr_eval_string("{valueparam }"));

fclose(file_stream);

return 0;

  总结:不是很难的代码,只是编写过程中学会举一反三,不拘泥于一种文件操作方法。

最新内容请见作者的github页:http://qaseven.github.io/

继续阅读