软件测试 中 LoadRunner 函数中的几个陷阱 1、atof 在 loadrunner 中如果直接用 float f; f=atof("123.00"); lr _output_message("%f",f); 输出的结果会是1244128.00,根本不是我们想要的。 因为float,double型在不同的平台下长度不一样,所以在loadrunner

软件测试LoadRunner函数中的几个陷阱

1、atof

  在loadrunner中如果直接用

  float f;

  f=atof("123.00");

  lr_output_message("%f",f);

  输出的结果会是1244128.00,根本不是我们想要的。

  因为float,double型在不同的平台下长度不一样,所以在loadrunner中调用atof需要显式的声明这个函数。

  如下:

  doubleatof (const char *string);

  float f;

  f=atof("123.00");

  lr_output_message("%.2f",f);

  这样就能输出结果:123.00。

  其实,在LR关于atof的帮助文档描述中有提到这点,要求使用这个函数前“must be explicitly declared in Vugen scripts. ”,同样的要求也出现在atol函数的描述中。

  2、lr.save_string

  在LoadRunner中,使用.NET VUser时可以使用lr.save_string来存入一个变量,但是其使用方法却与通常使用的lr_save_string有区别,不小心的话容易“中招”。

  C语言的lr_save_string的定义如下:

  int lr_save_string (const char *param_value, const char *param_name);

  注意:参数值在前面,参数名在后面

  而.NET VUser的lr.save_string的参数使用恰好相反,参数名在前面,参数值应该放到后面。

  但是LR的帮助文档并没有关于lr.save_string的定义,如果在脚本中选中“lr.save_string”,然后按F1,则直接蹦到lr_save_string的定义描述中,极容易误导人!

  3、ftp_put

  ftp_put 是LoadRunner中的FTP函数,用于上传文件到FTP服务器。定义如下:

  int ftp_put ( char *transaction, LAST);

  查看LR的帮助文档可获得如下例子:

  // Send the file "ftp_file.txt" to the for_jon directory.

  ftp_put("Ftp_Put",

  "PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",

  ENDITEM ,

  LAST);

  当你兴匆匆地以为拿过来修改一下就可以用了的时候,LR却提示如下错误:

  Starting action Action.

  globals.h(101): Warning message:PATH=D:/ftp.txt is not ftp_put valid option

  globals.h(101): Debug message:Putting file test.txt in /Qdownload/test.txt, passive mode set to 0

  globals.h(101): Error -86026:Failed to open D:\LoadRunner\LRProject\lr_FTP1\test.txt for reading.

  globals.h(101): Error -86027:Failed to put data: 226 Transfer complete

  Abort was called from an action.

  提示错误是文件不能读,但是文件明明就不在错误所提示的D:\LoadRunner\LRProject\lr_FTP1\test.txt 中,而是在D:/ftp.txt。

  后来看到错误提示之前的一个Warning写道PATH=D:/ftp.txt is not ftp_put valid option,难道错误是这里引起的?查看帮助文档关于item_list的描述可知:

  item_list

  A list of all the items for this function. Enclose all entries with quotes.

  SOURCE_PATH: The file to upload to the FTP server.

  OR

  MSOURCE_PATH - Like SOURCE_PATH, but using wildcards to specify multiple files. If wildcards are not specified, all the files in the MSOURCE_PATH are uploaded.

  TARGET_PATH (optional) - the path and filename in which to place the file.

  if (M)SOURCE_PATH is specified, but TARGET_PATH is not specified, the file is stored in the root directory of the FTP server, with the original file name.

  MODE (optional) - Retrieval mode ASCII or BINARY (default).

  PASSIVE (optional) - Sets the communication protocol to Passive Mode FTP. To enable, pass "PASSIVE=TRUE".

  ENDITEM - Marks the end of the list. (no quotes)

  原来是SOURCE_PATH而不是例子所说的PATH,好吧,等你改成SOURCE_PATH后,如下所示:

  // Send the file "ftp_file.txt" to the for_jon directory.

  ftp_put("Ftp_Put",

  "SOURCE_PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",

  ENDITEM ,

  LAST);

  兴匆匆地以为就行了,一运行又报错:

  globals.h(101): Error -86025:Put failed; 550 /pub/for_jon: Not a regular file

  原来这次是TARGET_PATH的问题,再看LR的帮助文档:

  TARGET_PATH (optional) - the path and filename in which to place the file.

  if (M)SOURCE_PATH is specified, but TARGET_PATH is not specified, the file is stored in the root directory of the FTP server, with the original file name.

  原来TARGET_PATH要包含文件名,因此改成:

  // Send the file "ftp_file.txt" to the for_jon directory.

  ftp_put("Ftp_Put",

  "SOURCE_PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon/ftp_file.txt", "MODE=ASCII",

  ENDITEM ,

  LAST);

  这次终于行了。

  同样的,在ftp_put_ex函数中也有类似的错误:

  In the following example, the ftp_get_ex function gets the file ftp_file.txt from the FTP server.

  // Send the file "ftp_file.txt" to the for_jon directory.

  ftp_put_ex(&ftp, "Ftp_Put",

  "PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",

  ENDITEM,

  LAST);

  而且例子代码写的是“ftp_put_ex”, 描述例子时却说的是“ftp_get_ex”。

最新文章

  1. SQL Server 2012 Managed Service Account
  2. css3伪类温故知新
  3. 飘逸的python - 增强的格式化字符串format函数
  4. SQL判断某列中是否包含中文字符、英文字符、纯数字 (转)
  5. 一颗躁动的心---下决心从SLAM开始,不钻研嵌入式底层了
  6. go 应用程序性能测试
  7. Java Concurrency - ThreadFactory, 使用工厂方法创建线程
  8. C语言中的%0nd,%nd,%-nd
  9. binder
  10. 给一个非常长的字符串str 另一个字符集比方{a,b,c} 找出str 里包括{a,b,c}的最短子串。要求O(n)
  11. jQuery进行简单验证的正则表达式
  12. Java的绝对路径和相对路径
  13. 【转载】目前主流过滤XSS的三种技术
  14. hibernate封装Until工具类
  15. IDEA启动项目内存溢出
  16. [转]Oh My Zsh,安装,主题配置
  17. 软件工程(五)UML
  18. 20.pipe
  19. C语言sscanf和sprintf输入输出使用及Strlen、Memset解释
  20. Eltwise层解析

热门文章

  1. POJ1845 Sumdiv [数论,逆元]
  2. python Tkinter 写一个弹球的小游戏
  3. Binary Tree Longest Consecutive Sequence -- LeetCode
  4. POJ3480 John 博弈论 anti-nim anti-SG
  5. HDU 4388 Stone Game II 博弈论 找规律
  6. [CODECHEF]TREECNT2
  7. 【拓扑排序】CDOJ1635 琵琶弦上说相思,当时明月在,曾照彩云归
  8. File I/O知识点
  9. 20172333 2017-2018-2 《Java程序设计》第3周学习总结
  10. Fatal error: Call to undefined function mb_detect_encoding()