做软件测试工程师的小伙伴应该都知道Recording Options设置在进行录制时,首先要对录制的一些参数进行设置,只有将这些参数设置好才能录制并生成需要的脚本。首先在Recording Options对话框中,选择Recording选项卡。Recording Level包含两种录制模式:HTML-based script和URL-based script,如图3-15所示,默认情况下选中HTML-based script录制方式。当然,两种录制模式也存在差别。
图3-15 Recording选项卡
单击【HTML Advanced…】按钮,弹出【Advanced HTML】对话框,如图3-16所示,在该对话框中关于HTML-based script脚本方式又有两种:“A script describing user actions”和“A script containing explicit”。
图3-16 HTML-based脚本录制方式
A script describing user actions:模拟用户行为录制,即GUI录制,把用户每一步的操作显示出来,最后生成的脚本非常直观并且会将上下文的一些敏感信息记录下来。它创建URL(web_url)、link(web_link)、image(web_image)和提交表单(web_submit_form)。
下面以A script describing user actions方式录制一个登录的功能,录制后的代码如下:
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(4);
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=1", ENDITEM,
"Name=login.x", "Value=65", ENDITEM,
"Name=login.y", "Value=8", ENDITEM,
LAST);
return 0;
从生成的代码中可以看到,在录制时只做了两个操作,生成的代码也只有两个函数,也即这种录制模式只录制用户的操作,其它的内容不会被录制。使用的提交信息函数为web_submit_form()。
A script contaning explict URLs only:录制所有links(链接)、images(图片)和URL(web_url),但不创建web_link、web_image和提交表单(web_submit_form)。这种录制方式生成的脚本不直观。
下面以A script contaning explict URLS only方式录制一个登录的功能,录制后的代码如下:
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value=108748.859052248ffQDHzQptDHfDDfzcpzVzzcf", ENDITEM,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=1", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=53", ENDITEM,
"Name=login.y", "Value=10", ENDITEM,
LAST);
return 0;
从生成的代码中可以看到,同样的提交登录的信息但使用的函数为web_submit_data(),不再以表单的方式提交,而web_submit_form()函数则是以表单的信息进行提交的,该函数运行时,首先在页面上去查找表单,再提交数据,而web_submit_data()则不需要,直接向服务器发送要提交的数据。
但在录制过程中很可能会录制到一些非HTML的元素(如Java小程序、XML、ActiveX元素、JavaScript),这些非HTML元素主要用于包含或去获取自己的一些资源,例如,JavaScript的JS文件用于调用加载多个图片。对于这类非HTML的元素,录制时有三种方式:
Record within the current script step:在录制时对于非HTML资源并不会生成一个新的功能。它列出所有相关资源的参数,如web_url、web_link和web_submit_data。这些web功能的参数使用EXTRARES标示。
如以下代码:
web_url("index.asp",
"URL=http://www.daisy.com/index.asp",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"Url=http://www.daisy.com/ScrollApplet.class", "Referer=", ENDITEM,
"Url=http://www.daisy.com/board.txt", "Referer=", ENDITEM,
"Url=http://www.daisy.com/nav_login1.gif", ENDITEM,
...
LAST);
Record in separate steps and use concurrent groups:在一个组中记录这些单独的步骤,为每个非HTML资源创建一个新的功能(但不包括一些页面的功能,如web_url、web_link等)。所有的web_url资源都将放置并行组中(并行组由web_concurrent_start和web_concurrent_end进行标示)。
如以下代码:
web_url("index.asp",
"URL=http://www.daisy.com/index.asp",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
web_concurrent_start(NULL);
web_url("ScrollApplet.class",
"URL=http://www.daisy.com/ScrollApplet.class",
"Resource=1",
"RecContentType=application/octet-stream",
"Referer=",
LAST);
web_url("board.txt",
"URL=http://www.daisy.com/board.txt",
"Resource=1",
"RecContentType=text/plain",
"Referer=",
LAST);
web_concurrent_end(NULL);
Do not record:不记录,对于非HTML元素不记录。
注意:使用HTML-Based模式录制时,VuGen插入目标帧到web_url函数中时,VuGen会在run-time运行的浏览器中和结果报告中显示页面的正确性。
如以下代码:
web_url("buttonhelp.gif",
"URL=http://www.hplab.com/home?com/rstr?BV_EngineID...,
"TargetFrame=main",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.hplab.com/home?...
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
URL-based script方式:将每条客户端发出的请求录制成一条语句,对LoadRunner来说,在该模式下,一条语句只能建立一个到服务器的连接,并将通信过程中的很多隐藏的信息都录制出来(如session、cookie)。LoadRunner提供了web_concurrent_start()和web_concurrent_end()函数模拟URL-based script的工作方式。
下面以URL-based script方式录制一个登录的功能,录制后的代码如下:
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
LAST);
web_concurrent_start(NULL);
web_url("header.html",
"URL=http://127.0.0.1:1080/WebTours/header.html",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t2.inf",
"Mode=HTTP",
LAST);
web_url("welcome.pl",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
web_concurrent_end(NULL);
web_concurrent_start(NULL);
web_url("hp_logo.png",
"URL=http://127.0.0.1:1080/WebTours/images/hp_logo.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://127.0.0.1:1080/WebTours/header.html",
"Snapshot=t3.inf",
LAST);
web_url("webtours.png",
"URL=http://127.0.0.1:1080/WebTours/images/webtours.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://127.0.0.1:1080/WebTours/header.html",
"Snapshot=t5.inf",
LAST);
web_concurrent_end(NULL);
web_concurrent_start(NULL);
web_url("home.html",
"URL=http://127.0.0.1:1080/WebTours/home.html",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Snapshot=t6.inf",
"Mode=HTTP",
LAST);
web_url("nav.pl",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Snapshot=t7.inf",
"Mode=HTTP",
LAST);
web_concurrent_end(NULL);
web_url("mer_login.gif",
"URL=http://127.0.0.1:1080/WebTours/images/mer_login.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t8.inf",
LAST);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t9.inf",
"Mode=HTTP",
ITEMDATA,
"Name=userSession", "Value=108749.254191981ffQDHiQpHzcfDDfzcpHDifHf", ENDITEM,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=1", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=63", ENDITEM,
"Name=login.y", "Value=9", ENDITEM,
LAST);
web_concurrent_start(NULL);
web_url("nav.pl_2",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t10.inf",
"Mode=HTTP",
LAST);
web_url("login.pl_2",
"URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t12.inf",
"Mode=HTTP",
LAST);
web_concurrent_end(NULL);
web_concurrent_start(NULL);
web_url("flights.gif",
"URL=http://127.0.0.1:1080/WebTours/images/flights.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t11.inf",
LAST);
web_url("itinerary.gif",
"URL=http://127.0.0.1:1080/WebTours/images/itinerary.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t13.inf",
LAST);
web_url("signoff.gif",
"URL=http://127.0.0.1:1080/WebTours/images/signoff.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t14.inf",
LAST);
web_url("in_home.gif",
"URL=http://127.0.0.1:1080/WebTours/images/in_home.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t15.inf",
LAST);
web_concurrent_end(NULL);
return 0;
在图3-15中选择URL-based script选择,单击【URL Advanced…】,弹出【Advanced URL】对话框,如图3-16所示。关于URL的高级设置有两种方式:“Create concurrent groups for resources their source HTML page”和“Use web_custom_request only”。
Create concurrent groups for resources their source HTML page:将捕获所有HTML页面的资源,并将其保存在并发组中(并发组使用web_concurrent_start和web_concurrent_end statements两个函数标识),如果不选中该选项时,HTML页面资源将会分成独立的、单独的web_url步骤,但并不放入并行组中。
如以下代码:
web_concurrent_start (NULL);
...
web_url("Click Here For Additional Restrictions",
"URL=http://www.hplab.com/restrictions.html",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.hplab.com/home?...
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
web_url("buttonhelp.gif",
"URL=http://www.hplab.com/home?com/rstr?BV_EngineID...,
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.hplab.com/home?...
"Snapshot=t5.inf",
"Mode=HTTP",
LAST);
...
web_concurrent_end (NULL);
Use web_custom_request only:如果录制的是非浏览器的应用程序,可以设置VuGen自定义HTTP请求,在LoadRunner中使用web_custom_reques函数来实现,不管内容如何。
如以下代码:
web_custom_request("www.hplab.com",
"URL=http://www.hplab.com/",
"Method=GET",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
LAST);
选择HTML-based script还是URL-based script,应该根据实际需要进行,下面是一些常见的参考原则:
1)基于浏览器的应用程序推荐使用HTML-based script。
2)不是基于浏览器的应用程序推荐使用URL-based script。
3)如果基于浏览器的应用程序中包含了JavaScript,并且该脚本向服务器发送了请求,比如DataGrid的分页按钮等,推荐使用URL-based script。
4)基于浏览器的应用程序中使用了HTTPS安全协议,建议使用URL-based script。如果使用HTML-based script模式录制后不能成功回放,可以考虑改用URL-based script模式来录制。因为这种情况多是由上面所列举的原因所引起的。
本章主要介绍了关于“Recording Options如何设置选项卡”的内容,大家喜欢的话记得每天来这里和小编一起学习涨薪技能哦。(笔芯)
附:川石信息全国校区最新开班时间,课程资料获取13691729932(微信同号)。