转:Loadrunner日积月累
上一篇 / 下一篇 2013-11-25 16:38:43 / 个人分类:loadrunner
把每天的收获都记录下来,免得上岁数的人记性差,忘的多。时常看一看,记在心里。
还是那句话:脚踏实地的走好每一步,想着未来的小小目标,努力前进,日积月累。
希望通过不屑的努力,能在未来的某一天,在我喜欢的领域上,取得不同于别人的成果,加油!
开始把.
一、通过web_set_user解决Windows登录验证问题。
The web_set_user function is a Service function that specifies a
login string and password for a Web server or proxy server. It can
be called more than once if several proxy servers require
authentication. web_set_user overrides the run-time proxy
authentication settings for user name and password.
When you log onto a server that requires user and password
validation, VuGen records a web_set_user statement containing the
login details. However, there are some more stringent,
authentication methods for which VuGen is unable to insert
web_set_user statements. See User Authentication for more detail.
In such cases, you can add web_set_user into your script.
manually.
When you run the script, LoadRunner automatically submits the user
authorization along with every subsequent request to that server.
At the end of the script, LoadRunner resets the
authorization.
例子:web_set_user("mercury", "mercury", "mansfield:80");
如果要进行域验证的话,需要在用户名前面加上域名,如web_set_user("domain\\mercury", "mercury",
"mansfield:80");
二、关于时间、日期格式的设置
Datetime Format Codes
%a day of week, using locale's abbreviated weekday names
%A day of week, using locale's full weekday names
%b month, using locale's abbreviated month names
%B month, using locale's full month names
%c date and time as %x %X
%d day of month (01-31)
%H hour (00-23)
%I hour (00-12)
%j number of day in year (001-366)
%m month number (01-12)
%M minute (00-59)
%p locale's equivalent of AM or PM, whichever is appropriate
%S seconds (00-59)
%U week number of year (01-52), Sunday is the first day of the
week. Week number 01 is the first week with four or more January
days in it.
%w day of week; Sunday is day 0
%W week number of year (01-52), Monday is the first day of the
week. Week number 01 is the first week with four or more January
days in it.
%x date, using locale's date format
%X time, using locale's time format
%y year within century (00-99)
%Y year, including century (for example, 1988)
%Z time zone abbreviation
%% to include the "%" character in your output string
例子:
lr_save_datetime("today is %Y-%B-%d", DATE_NOW , "today");
lr_output_message(lr_eval_string("{today}"));
英文操作系统中的执行结果:today is 2007-April-06
中文操作系统中的执行结果:today is 2007-四月-06
str=rand(); //生成任意随机数
str=rand() 0 //生成最大值为200的随机数
str=rand()0+200 //生成200-300之间的随机数
当脚本需要在多种场景下运行时,可以通过参数化事务名称来区分事务时间。下面的脚本将vusergroup作为事务名称:
int id, scid;
char* vuser_group;
char str[]="";
lr_whoami(&id, &vuser_group, &scid);
lr_message( "Group: %s, vuser id: %d, scenario id %d", vuser_group, id, scid);
strcat(str,vuser_group);
lr_start_transaction(str);
......
lr_end_transaction(str,LR_AUTO);
lr_whoami
在脚本中的RTS中的“continue on error”用于脚本级别的设置,而通过本函数可以灵活的在脚本中控制错误处理,当出现错误时是否终止脚本运行,默认是出错时停止的。
其中的错误级别:
0:Terminate script. execution upon database access errors.(default)
1:Continue script. execution upon database access errors, but issue a warning.
脚本示例:
lr_continue_on_error(0);
lrd_stmt(Csr1, "select..."...);
lrd_exec(...);
lr_continue_on_error(1);
vuser_init() {
LPCSTR server;
LPCSTR user = "Tom";
LPCSTR password = "pwd";
LPCSTR connect[10];
server=lr_get_attrib_string("host");
if (server==NULL){
lr_error_message("Failed to login. Unknown host.\n");
return(0);
}
sprintf(connect,"%s, %s, %s", user, password, server);
lr_message("%s", connect);
return 0;
}
在脚本目录的out\output.txt中打印内容如下:
tomh, pwd, sun2 [MsgId: MMSG-17999]
运行的命令:
mdrv.exe -usr "D:\Program Files\MI\Mercury LoadRunner\scripts\test\TestScript\TestScript.usr" -out "D:\Program Files\MI\Mercury LoadRunner\scripts\test\TestScript\out" -host sun2 -loop 4 -time 1.5
命令行分析函数
lr_get_attrib_double | 检索脚本命令行中使用的 double 类型变量。 |
lr_get_attrib_long | 检索脚本命令行中使用的 long 类型变量。 |
lr_get_attrib_string | 检索脚本命令行中使用的字符串。 |
信息性函数
lr_user_data_point | 录制用户定义的数据示例。 |
lr_whoami | 将有关 Vuser 的信息返回给 Vuser 脚本。不适用于应用程序管理。 |
lr_get_host_name | 返回执行 Vuser 脚本的主机名。 |
lr_get_master_host_name | 返回运行 LoadRunner Controller 或优化控制台的计算机的名称。不适用于应用程序管理。 |
字符串函数
lr_eval_string 将所有出现的参数替换为其当前值。
lr_save_string 将以 NULL 结尾的字符串保存到参数中。
lr_save_var 将可变长度字符串保存到参数中。
使用lr_save_string要将以 NULL 结尾的字符串保存到参数中,请使用
lr_save_string。要保存可变长度的字符串,请使用 lr_save_var
并指定要保存的字符串的长度。
对于 LoadRunner,默认的运行时设置支持 VuGen 的调试环境和Controller
的负载测试环境。默认设置为:
思考时间:在 VuGen 中为“关闭”,而在 Controller 中为“按录制参数回放”。
日志:在 VuGen 中为“标准”,而在 Controller 中为“关闭”。
下载非 HTML 资源:在 VuGen 和 Controller 中均为“已启用”。
九、Runtime Settings中的日志设置
Enable Logging启用日志记录
该选项将在回放期间启用自动日志记录 - VuGen 将写入日志消息,您可以在执行日志中查看这些消息。该选项仅影响自动日志记录和通过
lr_log_message 出的日志消息。仍会发出使用 lr_message、lr_output_message
和lr_error_message 手动发送的消息。
如果在“常规运行时设置”文件夹中将“错误处理”设置为“出现错误时仍继续”,则错误消息仍将被发送到“输出”窗口。如果修改了脚本的“日志详细级别”,
lr_message、lr_output_message 和lr_log_message 函数的行为将不会更改 —
这些函数将继续发送消息。
脚本示例:
Action()
{
lr_log_message("lr_log_message");
lr_message("lr_message");
lr_output_message("lr_output_message");
//lr_error_message("Unable to login to secure computing");
return 0;
}
不激活Enable Logging时的运行结果:
lr_message
Action.c(8): lr_output_message
Vuser Terminated.
如果激活Enable Logging并且设置send message only when error
occur,则正常日志没有打印。
Just In Time Log mode.
Log messages will be sent only when an error occurs.
To change this behavior, look at the Log tab in Run Time
Settings.
如果把lr_error_message语句前的注释去掉,则会将所有日志打印出来
Start auto log messages stack - Iteration 1.
Starting action Action.
lr_log_message
lr_message
Action.c(8): lr_output_message
Action.c(9): Error: Unable to login to secure computing
End auto log messages stack.
在脚本的Runtime Settings中的日志设置是针对整个脚本而言,可以通过lr_set_debug_message在脚本中进行灵活设置。
VuGen 日志事件(标准、参数替换等)的等级也称为消息类。有五个消息类:“简要”、“扩展”、“参数”、“结果数据”和“完全跟踪”。
可以使用 lr_set_debug_message 函数手动设置脚本内的消息类。如果您希望仅接收关于脚本的一小部分的调试信息,该设置非常有用。
例如,假设将日志运行时设置设为“标准日志”,并且需要获得脚本的特定部分的扩展日志。您可以使用 lr_set_debug_message函数在脚本中的所需位置设置扩展消息类。必须再次调用该函数以指定扩展模式的类型(“参数”、“结果数据”或“完全跟踪”)。通过调用 lr_set_debug_message 并指定“简要”模式,可返回到“标准日志”模式。
In this example, the lr_set_debug_message function enables the full trace option just before a call to lrd_fetch, which the user needs to debug because it has been giving unexpected results.
The second invocation of lr_set_debug_message resets the debug level to what it was formerly, by turning off (LR_SWITCH_OFF) the Extended message level.
Note that the two values for message level, LR_MSG_CLASS_EXTENDED_LOG and LR_MSG_CLASS_FULL_TRACE, have been logically ORed together.
lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_ON );
rc = lrd_fetch(Csr1, 1, 1, 0, PrintRow3);
if (rc>2000)
lr_debug_message(LR_MSG_CLASS_FULL_TRACE, "Fetch failed returned %d", rc);
lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_FULL_TRACE, LR_SWITCH_OFF );
十一、关于多线程的运行方式
Vuser
支持多线程环境。多线程环境的主要优势是每个负载生成器都能运行多个Vuser。只有线程安全协议才能按线程运行。(不适用于应用程序管理工具)
Controller 和优化控制台使用驱动程序(例如 mdrv.exe 或
r3vuser.exe)来运行Vuser。如果按进程运行每个 Vuser,则对于每个 Vuser
实例,都将反复启动(和加载)同一驱动程序并将其加载到内存中。将同一驱动程序加载到内存中会占用大量 RAM
(随机访问内存)及其他系统资源。这就限制了可以在任一负载生成器上运行的 Vuser 数。或者,如果按线程运行每个
Vuser,Controller 为每 50 个 Vuser(默认情况下)仅启动驱动程序(如 mdrv.exe)的一个实例。该驱动进程
/ 程序将启动几个Vuser,每个 Vuser 都按线程运行。这些线程 Vuser
将共享父驱动进程的内存段。这样做就不需要多次重新加载驱动程序 / 进程,节省了大量内存空间,从而可以在一个负载生成器上运行更多的
Vuser。
注意: 下列协议不是线程安全协议:Sybase-Ctlib、Sybase-Dblib、Informix、Tuxedo 和
PeopleSoft-Tuxedo。
“回放日志”中使用了不同颜色的文本。
. 黑色:标准输出消息
. 红色:标准错误消息
. 绿色:用引号括起来的文字字符串(例如 URL)
. 蓝色:事务信息(开始、结束、状态和持续时间)
. 橙色:迭代的开始和结束。
如果双击以操作名开始的行,则光标将会跳到生成的脚本中的相应步骤上。
十三、从 UNIX 命令行运行 Vuser 脚本
使用 VuGen 开发基于 UNIX 的 Vuser 时,必须检查录制的脚本是否运行在UNIX
平台上。要验证脚本是否正确运行,请执行下列步骤:
1 从 VuGen 对录制的脚本进行测试,以检查该脚本是否在基于 Windows 的系统上正确运行。
2 将 Vuser 脚本文件复制到 UNIX 驱动器。
3 在 UNIX 计算机上通过使用 verify_generator 来检查 Vuser 的设置。
4 从 UNIX 命令行测试脚本,使用 run_db_vuser shell 脚本,在 Vuser
脚本目录中以独立模式运行要测试的脚本:run_db_vuser.sh script_name.usr
转载:http://blog.sina.com.cn/s/blog_68f2677f0100vbly.html
TAG:
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | 3 | 4 | 5 | 6 | ||||
7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
28 | 29 | 30 |
我的存档
数据统计
- 访问量: 430064
- 日志数: 133
- 建立时间: 2013-07-02
- 更新时间: 2014-09-17