webInject中文手册
一系统框架
WebInject为perl语言编写,其系统框架如下:
webInject包含webInject Engine,可以用命令行调用,或者使用GUI调用webInject Engine. webInject Engine对应代码文件为webinject.pl.
二 webInject使用
webInject可以使用GUI运行以及命令行运行.下面步骤为gui运行,command运行具体参看: /manual.html
步骤一:下载webInject: /download.html
步骤二:解压,例如C:/ webinject
步骤三:双击webinjectgui.exe运行webinject自带的gui.
步骤四:点击run,运行默认配置config.xml
三配置
3.1 config.xml
Config.xml用于配置测试项目,config.xml指定webInject运行哪几个test case并配置一些运行中使用的常量.config.xml是GUI运行时默认的配置文件名称.在命令行运行webInject时候,用户可以指定自己的配置文件.
下面讲述config,xml中使用的各类参数.
3.1.1 Proxy(代理)
在config.xml中,配置http request代理.代码如下:
<proxy>http://127.0.0.1:8080</proxy>
如果配置需要验证的代理服务器,代码中加入用户名+密码.代码如下:
<proxy>http://username:password@127.0.0.1:8080</proxy>
3.1.2 useragent(User-agent翻译为用户代理)
User-agent 字段指的是每个request的自身的标志符,相当于request的身份证号码.默认的user-agent为webInject
<useragent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.0)</useragent>
3.1.3 httpauth(http验证)
对于需要http验证,配置如下:
<httpauth>:80:my_realm:foo:welcome</httpauth>
<!--[if !supportLists]-->3.1.4<!--[endif]-->baseurl(常量baseurl) <baseurl>http://myserver</baseurl>
3.1.5 globalhttplog(httplog配置)
参数yes,记录所有的test case运行过程中的http log
参数onfail,只记录失败的test case的http log.
3.1.6 comment(注释)
<comment>this will be ignored</comment>
<!--[if !supportLists]-->3.1.7<!--[endif]-->timeout(超时时间)
定义http响应的timeout时间(单位:second),如果test case中的response 相应超过设定的timeout时间.这个test case表明为失败.默认配置为180秒.
<timeout>10</timeout>
3.1.8 reporttype(报告形式)
这个配置项,用来指定输出的报告以何种形式显示.这里可以指定外部程序作为显示插件.例如:
<reporttype>mrtg</reporttype>
<reporttype>nagios</reporttype>
<!--[if !supportLists]-->3.1.8<!--[endif]-->globatimeout
这个配置项用于nagios 插件,当所有的case通过,但是时间超过globaltimeout 时间,警告消息将发送至nagios.
<globaltimeout>10</globaltimeout>
<!--[if !supportLists]-->3.1.9<!--[endif]-->Gnuplot
使用此参数,配置webinject使用的gnuplot产生相应时间图表.
<gnuplot>/usr/bin/gnuplot</gnuplot>
3.1.10 standaloneplot
使用webinject.pl生成png图片.此参数只对gui模式下有效.
<standaloneplot>on</standaloneplot>
<!--[if !supportLists]-->3.2<!--[endif]-->测试用例配置testcase.xml.
配置文件中,配置测试用例文件.代码如下:
<testcasefile>tests_1.xml</testcasefile>
<testcasefile>tests_2.xml</testcasefile>
<testcasefile>tests_3.xml</testcasefile>
Note:可以使用相对路径.
3.3 命令模式(指定自定义的config 文件)
webInject engine(webinject.pl)可以在命令模式下直接调用.
webinject.pl [-c|--config config_file] [-o|--output output_location] [-n|--no-output] [testcase_file [XPath]]
命令模式下,可以直接指定测试用例.
perl webinject.pl mytests.xml
如果没有指定测试用例,将会查找config.xml中配置的测试用例,如果没有测试用例配置,将会查找testases.xml文件.如果还是没有,将会报错.
下面的命令直接执行mytests.xml中的第二个case.
perl webinject.pl mytests.xml testcases/case[2]
<!--[if !supportLists]-->4<!--[endif]-->测试用例
测试用例为xml 文档,文档中只有id 以及url为必选项,其他为可选项,如果没有验证参数,pass的标准为http response在范围100-399以内.
最简单的测试用例配置如下:
<case
id="1"
url="http://myserver/test/test.html"
/>
Result.html中为可以得到最详细的细节.
5.3 显示结果于result.xml中
6 session的处理以及状态管理
6.1 summary
http 为无状态协议,因此web应用使用不同的方法来管理状态.一种方法为使用cookies,另一种方法为使用session id.
下面介绍如何使用session id :
1 在test case中设置如下代码:
parseresponse="JSESSIONID=|;"
这段代码将捕捉上一个上一个response的session id,凡是http header中左面为JSESSIONID=右面为;里面的内容将被赋值到变量{PARSEDRESULT}中.
当url中使用{PARSEDRESULT},webinject将自动替代捕获到的sessionid.
url="http://myserver/search.jsp?value=123&;JSESSIONID={PARSEDRESULT}" 上述代码下:如果上一个response的header为
Set-Cookie: JSESSIONID=16CD67F723A6D2218CE73AEAEA899FD9; Path=/
在发送过去的url将被解析为:
http://myserver/search.jsp?value=123&;JSESSIONID=16CD67F723A6D2218CE7 3AEAEA899FD9
7 webInject的不足
1 不支持中文(webinject支持中文的方法)
2 异常处理不好(config.xml中配置错误路径的testcase.xml,run gui后界面无反应)
3 不执行response中的脚本.(javascript,vbscript等)
4 不支持http 重定向。