十五年测试老手,长期负责WEB\APP 项目测试,目前主要负责团队管理工作。

LoadRunner函数中的几个陷阱

上一篇 / 下一篇  2011-11-17 22:52:16 / 个人分类:loadrunner

查看( 1544 ) / 评论( 3 )
1、atof 51Testing软件测试网/HO,H*jZ'b;QC
  在[url=]LoadRunner[/url]中如果直接用:51Testing软件测试网9nv#K:n"Nk1Js

S B7{9? FP,E0   float f;
n)P^{Ra7tRmG0   f=atof("123.00");
d3N;KUmi q/|0   lr_output_message("%f",f);
51Testing软件测试网-a(w|$P'Zt B-~H
51Testing软件测试网 x.q%n)VL `
  输出的结果会是1244128.00,根本不是我们想要的。51Testing软件测试网roz?&Q:Nx
  因为float,double型在不同的平台下长度不一样,所以在loadrunner中调用atof需要显式的声明这个[url=]函数[/url]。
H!g'?,N l*EjB0   如下:
sH)|,`O!K0
51Testing软件测试网an?+[te%S#p
  doubleatof (const char *string);51Testing软件测试网{ zc(i8ME_
  float f;
"Dsm n ps pp }#u0   f=atof("123.00");
5z*rUC-S?1bN0   lr_output_message("%.2f",f);

1k3vGu2ppeH8|(K0
Y P^ElA0   这样就能输出结果:123.00。51Testing软件测试网m.EN J_p
  其实,在LR关于atof的帮助文档描述中有提到这点,要求使用这个函数前“must be explicitly declared in Vugen scripts. ”,同样的要求也出现在atol函数的描述中。
"K R&JU|0   2、lr.save_string51Testing软件测试网*P:a$q]a"[| h4l
  在LoadRunner中,使用.NET VUser时可以使用lr.save_string来存入一个变量,但是其使用方法却与通常使用的lr_save_string有区别,不小心的话容易“中招”。
FhE dn!D0   C语言的lr_save_string的定义如下:
1_ Iu#y+Q f:Z0
  int lr_save_string (const char *param_value, const char *param_name);
51Testing软件测试网 h2~6l+Q6] c

*q|I$f;C0W.m0   注意:参数值在前面,参数名在后面。
~Zl m6U,QB0   而.NET VUser的lr.save_string的参数使用恰好相反,参数名在前面,参数值应该放到后面。
TsuN3}s0   但是LR的帮助文档并没有关于lr.save_string的定义,如果在脚本中选中“lr.save_string”,然后按F1,则直接蹦到lr_save_string的定义描述中,极容易误导人!
w.A T~;l&b:D9vp`!W@0 3、ftp_put51Testing软件测试网i"@ zD2F5n C&h9hD
  ftp_put 是LoadRunner中的FTP函数,用于上传文件到FTP服务器。定义如下:
&mrhyu}0
  int ftp_put ( char *transaction, LAST);

(Fy)htX$S\ i0
'^I%ro_0   查看LR的帮助文档可获得如下例子:
)~V/Vg#B/w g V0
51Testing软件测试网&z;xNU@
  // Send the file "ftp_file.txt" to the for_jon directory.51Testing软件测试网D)G+@sR-oq5s
  ftp_put("Ftp_Put",
a,u8Mx(ZG%V8Ds*{0   "ATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",
[;wu hn J6U_0   ENDITEM ,51Testing软件测试网Ku6T;vF W~7R
  LAST);
51Testing软件测试网q*l-J/Ac'`'n)p

l8~u7z;l~'c0   当你兴匆匆地以为拿过来修改一下就可以用了的时候,LR却提示如下错误:51Testing软件测试网hU.[{eW
  Starting action Action.
$C m4vm/vGI_0   globals.h(101): Warning messageATH=D:/ftp.txt is not ftp_put valid option
"}.r0Jk b:f2DI0   globals.h(101): Debug messageutting file test.txt in /Qdownload/test.txt, passive mode set to 0
4x!]MGh+U.w8J{ ~2G0   globals.h(101): Error -86026:Failed to open D:\LoadRunner\LRProject\lr_FTP1\test.txt for reading.
6c+aP1JXn+N2zX5@0   globals.h(101): Error -86027:Failed to put data: 226 Transfer complete
q~ U8|1b q:I0   Abort was called from an action.51Testing软件测试网Ln2|W)e^ Neg/u
  提示错误是文件不能读,但是文件明明就不在错误所提示的D:\LoadRunner\LRProject\lr_FTP1\test.txt 中,而是在D:/ftp.txt。51Testing软件测试网hL:o*x!P{;l@b
  后来看到错误提示之前的一个Warning写道PATH=D:/ftp.txt is not ftp_put valid option,难道错误是这里引起的?查看帮助文档关于item_list的描述可知:
wGWh8M\6b5TQ0   item_list
3lm!R2B AXBx0   A list of all the items for this function. Enclose all entries with quotes.
t%Lhw"]TV0   SOURCE_PATH: The file to upload to the FTP server.
,VO B0J_0   OR51Testing软件测试网kF.R;Xky1xf j
  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.51Testing软件测试网'a"b1J'^M1^1J
  TARGET_PATH (optional) - the path and filename in which to place the file.
1Y9iB&A~Ap!`0   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.51Testing软件测试网sW.? L/qT
  MODE (optional) - Retrieval mode ASCII or BINARY (default).
2C i"j8mu(u)B0   PASSIVE (optional) - Sets the communication protocol to Passive Mode FTP. To enable, pass "ASSIVE=TRUE".
7eD#p@(Y#|$k0   ENDITEM - Marks the end of the list. (no quotes)51Testing软件测试网(m(H~ D6h3P
  原来是SOURCE_PATH而不是例子所说的PATH,好吧,等你改成SOURCE_PATH后,如下所示:51Testing软件测试网HDb6IL
51Testing软件测试网,uCg#Rp~.m
  // Send the file "ftp_file.txt" to the for_jon directory.51Testing软件测试网+S#H*`k zU@l*VZ
  ftp_put("Ftp_Put",
D-H.b2a abow"f*D0   "SOURCE_PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",
1`3SG `[TfZ0   ENDITEM ,51Testing软件测试网2v9r1[ ?-c},b D+v
  LAST);
51Testing软件测试网+p/O/M|-JJu\2kh#?

Dh/~ P4b4O?I IF}G0   兴匆匆地以为就行了,一运行又报错:
gU&\\2A8l.Q+l0   globals.h(101): Error -86025ut failed; 550 /pub/for_jon: Not a regular file51Testing软件测试网?g L(Snx
  原来这次是TARGET_PATH的问题,再看LR的帮助文档:
V(s d*UH QK `P-I0   TARGET_PATH (optional) - the path and filename in which to place the file.
"GvD \#]W0   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.51Testing软件测试网!L`/o{0\_K q
  原来TARGET_PATH要包含文件名,因此改成:
|+j1FevM\0

.C&e^%U0Nea7fb y"[0   // Send the file "ftp_file.txt" to the for_jon directory.
jv1GV#sI!x,`7Q"}s0   ftp_put("Ftp_Put",
&En4Th+w$@?'rM%Y8g0   "SOURCE_PATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon/ftp_file.txt", "MODE=ASCII",
s XsBe4OcJw.i0   ENDITEM ,
ov^XCEI0   LAST);
51Testing软件测试网4_:CYpIl#z

{%Fk0CYi1N0   这次终于行了。51Testing软件测试网%f9Z4Sg:_K
  同样的,在ftp_put_ex函数中也有类似的错误:
^&To b7e;b3s3D5[0

R.z {{5htO'wt0   In the following example, the ftp_get_ex function gets the file ftp_file.txt from the FTP server.
|6g Dl(Ch0   // Send the file "ftp_file.txt" to the for_jon directory.
P \ @@\2V3o0   ftp_put_ex(&ftp, "Ftp_Put",
o1L#{;{-D_lg0   "ATH=f:/ftp_file.txt", "TARGET_PATH=/pub/for_jon", "MODE=ASCII",
0GJ#r/rg Kye_0   ENDITEM,51Testing软件测试网,m7U*fJ#M&J}
  LAST);
51Testing软件测试网}!_2w M;p

$y+Am6] JxL9s!v0   而且例子代码写的是“ftp_put_ex”, 描述例子时却说的是“ftp_get_ex”。
P!P)y]I7YJ0   LR是非常优秀的性能测试工具,但是如果帮助文档中类似这样的错误比较多的话,对初学者而言就又多了一道学习的门槛:鉴别联机帮助信息的真伪的能力。

TAG:

零测试 零测试 发布于2011-11-18 08:39:58
学习了!感谢楼主和版主!
茶叶 夏日摸摸茶 发布于2011-11-18 14:29:33
支持一下!
thirfing的个人空间 thirfing 发布于2011-11-18 17:31:14
学习了,支持
我来说两句

(可选)

Open Toolbar