5.2.2 规划脚本结构
在录制时,用户可以选择哪些操作生成脚本在vuser_init、Action和vuser_end中,同时,也可以在录制时随时加入transaction的定义、注释和同步点。VU录制工具条如图5-3所示。
图5-3 VU录制工具条
5.2.3 HTTP Vuser中的URL mode和HTML mode
在录制之前,我们需要设置录制选项,如图5-4所示。
图5-4 VU录制设置选项
在默认情况下,选择“HTML-based script”,说明脚本中采用HTML页面的形式来表示,这种方式的Script脚本容易维护,容易理解,推荐以这种方式录制。
“URL-based script”说明脚本中的表示采用基于URL的方式,所有的HTTP的请求都会被录制下来,单独生成函数,所以URL模式生成的脚本会显得有些杂乱。
实例
以HTML模式录制,访问“http://newtours.demoaut.com/”网站会生成下面的脚本:
Action()
{
web_url("newtours.demoaut.com",
"URL=http://newtours.demoaut.com/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
return 0;
}
以URL模式录制同样的操作,会生成如下脚本:
Action()
{
web_url("newtours.demoaut.com",
"URL=http://newtours.demoaut.com/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
LAST);
web_url("logo.gif",
"URL=http://newtours.demoaut.com/images/nav/logo.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://newtours.demoaut.com/",
"Snapshot=t2.inf",
LAST);
web_url("html.gif",
"URL=http://newtours.demoaut.com/images/nav/html.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://newtours.demoaut.com/",
"Snapshot=t3.inf",
LAST);
web_url("boxad1.gif",
"URL=http://newtours.demoaut.com/images/nav/boxad1.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://newtours.demoaut.com/",
"Snapshot=t4.inf",
LAST);
........................................
..........................................
//经统计,录制生成的web_url函数有20个
return 0;
}
是选择HTML还是URL录制,有以下参考原则:
(1)基于浏览器的应用程序推荐使用HTML-based script。
(2)不是基于浏览器的应用程序推荐使用URL-based script。
(3)如果基于浏览器的应用程序中包含了JavaScript并且该脚本向服务器产生了请求,比如DataGrid的分页按钮等,也要使用URL-based script方式录制。
(4)基于浏览器的应用程序中使用了HTTPS安全协议,使用URL-based script方式录制。