zoukankan      html  css  js  c++  java
  • 软件测试中LoadRunner函数中的几个陷阱

    软件测试 中 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:LoadRunnerLRProjectlr_FTP1 est.txt for reading.

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

      Abort was called from an action.

      提示错误是文件不能读,但是文件明明就不在错误所提示的D:LoadRunnerLRProjectlr_FTP1 est.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、vsCode插件开发流程入门
    node中MySQL的安装与使用
    sublime使用插件
    Node.js基础知识梳理
    第5章-11 字典合并 (40分)
    我的考研心得-zju-se
    解决 重启tomcat上传的文件被自动删除或未重启过段时间也自动删除(deloy path)
    org.hibernate.InstantiationException: No default constructor for entity
    UE.delEditor is not a function问题原因及解决方法
    javaweb开发过程中遇到的问题
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4483049.html
Copyright © 2011-2022 走看看