loadrunner学习系列---脚本编写(2).docVIP

  • 0
  • 0
  • 约2.72千字
  • 约 5页
  • 2021-10-29 发布于四川
  • 举报
今天接着翻译上面关于LR脚本编写部分. VUser_Init部分 这里是Vuser_init部分的一些例子: 的User ID 下面显示了使用advapi32.dll的GetUserNameA函数获得的操作系统的用户ID char sUserID[1024]; // Maximum possible UserID length. long lUserIDSize = sizeof(sUserID)-1; int rc; rc=lr_load_dll(advapi32.dll); if( rc != 0 ){ lr_error_message(lr_load_dll of advapi32.dll failed. Aborted for rc=%d,rc); lr_abort(); }else{ GetUserNameA(sUserID, lUserIDSize); lr_message(UserID=%s, sUserID); } 所有的变量声明需要一块放到最上方。在vuser_init 部分创建的本地C变量(如 int或char)对部分的脚本是不可见的。所以使用lr_save_string函数来创建对所有脚本可用的全局参数。例子: char *itoa ( int value, char *str, int radix ); vuser_init(){ int x = 10; char buffer[10]; lr_save_string( itoa( x, buffer, 10) , pX ); lr_message ( int x = %s, lr_eval_string({pX} )); return 0; } ? ? 运行时设置的附加属性(Additional Attribute) 8.0版本引进了一个非常有价值的特性:在运行时设置中指定属性,这个属性可以对不同的虚拟用户组设置不同的值。 ? 下面的代码是从运行时设置的附加属性中读取名为“usertype”的参数。然后使用参数值来对应的设置全局的thinktime1变量。 int thinktime1=0; vuser_init() { LPCSTR strUsertype; // Define *str. strUsertype = lr_get_attrib_string(usertype); if (strUsertype==NULL){ lr_output_message(### Run-time Settings Additional Attribute usertype not specified. Cannot continue.); lr_abort(); }else{ lr_message(### Run-time Settings Additional Attribute usertype=\%s\, strUsertype ); if( strcmp( strUsertype,advanced) == 0 ){ thinktime1=2; } else if( strcmp( strUsertype,intermediate) == 0 ){ thinktime1=4; } else if( strcmp( strUsertype,basic) == 0 ){ thinktime1=8; } else{ lr_error_message(### ERROR: Value not recognized. Aborting run. ); lr_abort(); } } return 0; } ? Time Structure Fix(不知道怎么翻译,呵呵,“时间结构的解决“?) 根据知识库34195的文章,默认当前时间戳的毫秒部分不被更新,除非ftime使用的时间结构被重新定义: typedef long time_t; struct _timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; struct _timeb t; _tzset(); \\ 使用ftime设置变量 _ftime( t ); lr_message( Plus milliseconds: %u, t.millitm ); 控制信息的显示: 在运行时,当脚本的事务失败后继续,你怎么知道哪个用户失败了? 在每个失败的事务之后,发出一个能够唯一确定该用户的信息。 提供了一些函数来在运行时显示信息: ? //

文档评论(0)

1亿VIP精品文档

相关文档