......

LoadRunner技巧小集锦

上一篇 / 下一篇  2011-11-02 17:10:33

安装lr以后,录制脚本时,无法打开ie,但如果我先用ie打开一个网页,然后再录制,便可以打开ie,但录制过程中一直是o events,录制脚本中只有一句return 0,总结原因是当前默认浏览器不是IE,设置一下就可以,工具--Internet选项--程序--默认的web浏览器后面点击"设为默认值"即可,如果该按钮为灰色表示当前ie是默认浏览器,如可点,刚表示不是.

 1、录制脚本中包含中文,出现乱码怎么办?7个重复
把录制选项中的Support charset选中UTF-8
录制脚本后,切换到树视图中,打开相应的脚本页面。在右侧的PageView中录制的脚本呈现中文版式,但是当切换到ServerResponse中,所有的中文全部换成的乱码,如勌缞仫訆
原因是服务器端没有把响应的编码设置为gb2312    
IIS中找到Web.Config文件,在<system.web>….</system.web>节加入<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312"/>后再次录制脚本,乱码变中文。
2、录制到的脚本是空白的
有可能是由于录制的URL地址采用的是localhost的问题,改成分配的IP地址或127.0.0.1试试。
3、插入文本检查点步骤时,使用web_reg_find,通常TextPfxTextSfx中会包含双引号,需要进行转义(用斜杠),例如:
   web_reg_find("Search=Body",
   "SaveCount=Welcome",
 "TextPfx=
欢迎<a class=\"drop\" id=\"viewpro\" nMouseOver=\"showMenu(this.id)\">",
"TextSfx=</a>",
 LAST);

4、使用web_image_check插入图片检查点时需要主要设置Run-Time Setting中的Enable Image and text check选项:
 
使用web_find函数插入文本检查点也一样要做此设置
5性能测试往往需要准备大批量的数据,大批量数据的生成方法有很多种,常见的有:
     1)编写SQL语句来插入数据
      
2)使用DataFactory等专业的数据生成工具
      
3)通过LoadRunner录制回放的方式重复执行生成大批量数据
Tips:
使用DataFactory插入nchar数据类型的数据时会出现空值的情况,可以先修改数据库的数据类型设置,插完数据后再改回来
6、在录制脚本的过程中插入注释,录制后查看和理解脚本会更加方便。

7LoadRunner回放脚本时,在浏览器显示的中文是乱码
解决办法(1):
首先设置Run-Time Settings – Browser – Browser Emulation – User-Agent
然后设置IE
查看-编码-钩上自动选择UnicodeUTF-8)。

解决办法(2):
使用lr_convert_string_encoding函数来转换编码
下面是一个使用的例子:
lr_convert_string_encoding(lr_eval_string("{ReplyContents}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"ReplyMessage");
 web_submit_data("postreply.aspx_2", 
   "Action=http://127.0.0.1/postreply.aspx?infloat=1&topicid=2&&inajax=1",

              "Method=POST",

              "EncType=multipart/form-data",

              "RecContentType=text/xml",

              "Referer=http://127.0.0.1/showtopic-2.aspx",

              "Snapshot=t9.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=iconid", "Value=0", ENDITEM,

              "Name=title", "Value=", ENDITEM,

              "Name=wysiwyg", "Value=0", ENDITEM,

              "Name=checkbox", "Value=0", ENDITEM,

              "Name=message", "Value=[localimg=180,112]1[/localimg]\r\n\r\n{ReplyMessage}", ENDITEM,

              "Name=e_mediatyperadio", "Value=on", ENDITEM,

              "Name=sl_attachdesc", "Value=", ENDITEM,

              "Name=attachid", "Value=", ENDITEM,

              "Name=attachdesc", "Value=", ENDITEM,

              "Name=localid", "Value=", ENDITEM,

              "Name=attachdesc", "Value=", ENDITEM,

              "Name=localid", "Value=1", ENDITEM,

              "Name=attachdesc", "Value=", ENDITEM,

              "Name=localid", "Value=2", ENDITEM,

              "Name=emailnotify", "Value=on", ENDITEM,

              "Name=postreplynotice", "Value=on", ENDITEM,

              "Name=postfile", "Value=", "File=Yes", ENDITEM,

              "Name=postfile", "Value=D:\\\\图片收集\\\\It's about time.JPG", "File=Yes", ENDITEM,

              "Name=postfile", "Value=", "File=Yes", ENDITEM,

              "Name=uploadallowmax", "Value=10", ENDITEM,

              "Name=uploadallowtype", "Value=jpg,gif", ENDITEM,

              "Name=thumbwidth", "Value=300", ENDITEM,

              "Name=thumbheight", "Value=250", ENDITEM,

              "Name=noinsert", "Value=0", ENDITEM,

              LAST);

 

8、可以在LR测试脚本的目录中找到参数文件,直接修改参数文件

The parameter file is stored in the script. directory as .dat file extension.  It can be opened with a simple text editor like Notepad as it is stored in pure text format.  Therefore, you can manipulate the files via the Notepad.  You can also use office applications such as Microsoft Excel or OpenOffice.org Calc to work on the file.  This greatly the amount of work required for maintaining a long list of data.

9LR9.x启动VUGen时提示"Failed to connect to server"

After upgrading to LoadRunner 9.x I started getting a window popup which said "Failed to connect to server" every time I opened virtual user generator (vugen.exe).

The solution to this was to close virtual user generator and delete the [vugen.ini] file.

vugen.ini is found in the %systemroot% folder on yourWindowsPC (usually C:\WINDOWS or C:\WINNT).

Once you've deleted the file, virtual user generator will open without any issues and create a new vugen.ini file automatically.

10、怎样抓取有相同左右边界的动态value

例如:

stateID="d7lg0ehmjkkm6uin3s4boei7oq">

stateID="cvopakp46ftsf8mh6l37ti3ubm">

stateID="bv9mja8gtgr39ddibm5t9163re">

web_reg_sav

11、运行场景时提示“Step download timeout (120 seconds) has expired when downloading resource(s)”

vuser_init.c(12): Error -27728: Step download timeout (120 seconds) has expired when downloading non-resource(s)(出现个别,可以忽略)

vuser_init.c(12): Error -27727: Step download timeout (120 seconds) has expired when downloading resource(s). Set the "Step Timeout caused by resources is a warning" Run-Time Setting to Yes/No to have this message as a warning/error, respectively

如果觉得下载一个页面超过2分钟不是错误的话,可以在Run-Time设置中选择Preferences->Options,修改Step download timeout(sec)的时间

或者把“Step timeout caused by resources is a warning”设置为Yes,这样下载资源超时也只是作为警告,不作为错误提示,但是对于非资源的下载超时,则总是会提示错误的

12、用strtok函数分割字符串

需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数。

//Body response内容:<BODY><; PRE>//OK[8,7,5,15,6,5,0,4,0,3,0,3,2,0,0,0,1

web_reg_save_param取出“8,7,5,15,6,5,0,4,0,3,0,3,2,0,0,0,1”这一段,然后用strtok函数切割出一个个数字,第四个数字就是要找的值

例如:

extern char * strtok(char * string, const char * delimiters ); // Explicit declaration

char separators[] = ",";

char * token;

lr_save_string("1,2,3,4,5,6","str");

token = (char *)strtok(lr_eval_string("{str}"), separators); // Get the first token

if (!token) {

        lr_output_message ("No tokens found in string!");

        return( -1 );

    }

while (token != NULL ) { // While valid tokens are returned

        lr_output_message ("%s", token );

        token = (char *)strtok(NULL, separators); // Get the next token

    }

13LoadRunner没有购买webservice协议的license,只有http的,可不可以完全用http协议模拟webservice
可以,参考:

http://blog.testsautomation.com/2009/01/web-services-performance-using-loadrunner/

http://blog.testsautomation.com/2009/05/validating-web-service-response-with-xpath/

14、在场景设置中不忽略思考时间,但是在查看响应时间的时候怎样让LR自动在响应时间里减去思考时间?

analysis中找到了设置是否在报告中包含思考时间的地方做相应的设置即可:

15LoadRunner在运行过程中停掉1半虚拟用户

Another issue that I’m facing from time to time is that LoadRunner stops 50% of running users without any notification, issue, error message etc. I’ve find out that it happens only when running with log level set to ‘always send a message’. Because of that, I suggest to run with log level set to ‘Send message only when error occur’.

17测试RTMP协议应该在LoadRunner选择什么协议来录制?

flex协议


TAG:

 

评分:0

我来说两句

Open Toolbar