webInject中文手冊

webInject 手冊

系統框架

 WebInjectperl語言編寫,其系統框架如下:

webInject包含webInject Engine,可以用命令行調用,或者使用GUI調用webInject Engine. webInject Engine對應代碼文件爲webinject.pl.

 

webInject使用

webInject可以使用GUI運行以及命令行運行.下面步驟爲gui運行,command運行具體參看: http://www.webinject.org/manual.html

步驟一:下載webInject: http://www.webinject.org/download.html

步驟二:解壓,例如C:/ webinject

步驟三:雙擊webinjectgui.exe運行webinject自帶的gui.

步驟四:點擊run,運行默認配置config.xml

 

 

 

 

 

配置

3.1 config.xml

Config.xml用於配置測試項目,config.xml指定webInject運行哪幾個test case並配置一些運行中使用的常量.config.xmlGUI運行時默認的配置文件名稱.在命令行運行webInject時候,用戶可以指定自己的配置文件.

下面講述config,xml中使用的各類參數.

3.1.1 Proxy(代理)

config.xml,配置http request代理.代碼如下:

<proxy>http://127.0.0.1:8080</proxy>

如果配置需要驗證的代理服務器,代碼中加入用戶名+密碼.代碼如下:

<proxy>http://username:[email protected]:8080</proxy>

 

3.1.2 useragent(User-agent翻譯爲用戶代理)

User-agent 字段指的是每個request的自身的標誌符,相當於request的身份證號碼.默認的user-agentwebInject

<useragent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)</useragent>

3.1.3 httpauth(http驗證)

對於需要http驗證,配置如下:

<httpauth>www.fakedomain.com:80:my_realm:foo:welcome</httpauth>

 

3.1.4  baseurl(常量baseurl)

<baseurl>http://myserver</baseurl>

 

 

3.1.5 globalhttplog(httplog配置)

 

參數yes,記錄所有的test case運行過程中的http log

參數onfail,只記錄失敗的test casehttp log.

 

3.1.6 comment(註釋)

<comment>this will be ignored</comment>

3.1.7      timeout(超時時間)

定義http響應的timeout時間(單位:second),如果test case中的response相應超過設定的timeout時間.這個test case表明爲失敗.默認配置爲180.

<timeout>10</timeout>

 

3.1.8 reporttype(報告形式)

這個配置項,用來指定輸出的報告以何種形式顯示.這裏可以指定外部程序作爲顯示插件.例如:
<reporttype>mrtg</reporttype>
<reporttype>nagios</reporttype>

 

3.1.8  globatimeout

這個配置項用於nagios 插件,當所有的case通過,但是時間超過globaltimeout時間,警告消息將發送至nagios.
<globaltimeout>10</globaltimeout>

 

3.1.9  Gnuplot

使用此參數,配置webinject使用的gnuplot產生相應時間圖表.

<gnuplot>/usr/bin/gnuplot</gnuplot>

 

3.1.10 standaloneplot

使用webinject.pl生成png圖片.此參數只對gui模式下有效.

<standaloneplot>on</standaloneplot>

 

3.2  測試用例配置 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]

 

4              測試用例

  測試用例爲xml 文檔,文檔中只有id 以及url爲必選項,其他爲可選項,如果沒有驗證參數,pass的標準爲http response在範圍100-399以內.

     最簡單的測試用例配置如下:

<case

    id="1"

    url="http://myserver/test/test.html"

/>
編號

參數名稱

描述

1

Id

指定測試用例的執行順序編號

2

Description1

測試報告的描述

3

Description2

測試報告的描述

4

method

http request的方法,默認下爲get方法,可以設置爲post

5

url

可以使用ip地址或者主機名稱.

6

Posttype

指定上傳form的內容類型:

1 application/x-wwww-form-urlencoded(默認設置)

2 multipart/form-data

3 text/xml

4 application/soap+xml

7

postbody

"application/x-www-form-urlencoded"下爲text data,
“multipart/form-data”下爲perl code
"text/xml" or "application/soap+xml"下爲指定外部文件地址: postbody="file=>soap_payload.xml"

8

verifyresponsecode

 

指定response的正確驗證碼

9

verifypositive

 

使用perl正則表達式匹配驗證碼.

10

verifypositive2
同上

11

verifypositive3
同上

12

verifynegative
如果response中存在指定的錯誤碼,則這個response爲錯誤.

13

verifynegative1

 

同上

14

verifynextpositive

 

指定下一個responese的正確驗證碼,如果下一個response中不包含這個驗證碼,response錯誤.

15

verifynextnegative
指定下一個response的錯誤驗證碼,如果下一個response中包含此驗證碼,則這個response爲錯誤.

16

logrequest

設置當前case發送的http request是否記錄在log文件中.

17

logresponse

設置當前case接受的response是否記錄在log文件中.

18

parseresponse

常用於需要解析sessioncase,以及動態產生valuecase.

19

sleep

Case執行的間隔時間.

20

errormessage
如果case失敗,將會顯示指定的errormessage.

21

addheader
http request中加入header.

addheader="Foo: bar|Boo: far"

 

4.1 重複執行
重複執行測試用例代碼如下:
<testcases repeat="5">
4.2 xml文檔中的一些特殊字符
符號名稱
正確代碼
錯誤代碼
<

 

verifypositive="<OPTION SELECTED>APPLE"
verifypositive="/<OPTION SELECTED>APPLE"

 

"

 

verifypositive=' 'this' '

 

verifypositive=' "this" '

 

 

4.3常量設置
常量設置以{} config.xml中設置.例子如下:
如果test case中用到: url=http://myserver/test/login.jsp

config.xml中如下設置: <baseurl>http://myserver</baseurl>
Test case中可以如下重寫: url="{BASEURL}/test/login.jsp"
常量設置非常有用,特別是你的測試環境需要改變.比如上面中myserver的名字在不同的測試環境下不同.

 

5             通過以及失敗的標準

定義測試用例通過還是失敗.
5.1       Verifications(從內容中定義)
“verifypositive” 如果response中不包含此內容,則測試失敗
“verifynegative” 如果response中包含此內容,測試失敗.
Verifypositive以及verifynegative可以使用string或者正則表達式.
5.2       http response code
如果返回的http response code與指定的code相同則通過,反之不通過.

默認下通過範圍爲100-399

 

5 輸出結果

webInject的輸出結果有三個地方:

5.1 顯示結果於gui

5.2 顯示結果於result.html

 Result.html中爲可以得到最詳細的細節.

5.3 顯示結果於result.xml

 

6 session的處理以及狀態管理

6.1 summary

http 爲無狀態協議,因此web應用使用不同的方法來管理狀態.一種方法爲使用cookies,另一種方法爲使用session id.

下面介紹如何使用session id :

1 test case中設置如下代碼:

parseresponse="JSESSIONID=|;"

這段代碼將捕捉上一個上一個responsesession id,凡是http header中左面爲JSESSIONID=右面爲;裏面的內容將被賦值到變量{PARSEDRESULT}.

url中使用{PARSEDRESULT},webinject將自動替代捕獲到的sessionid.

url="http://myserver/search.jsp?value=123&;JSESSIONID={PARSEDRESULT}"
上述代碼下:如果上一個responseheader

Set-Cookie: JSESSIONID=16CD67F723A6D2218CE73AEAEA899FD9; Path=/
在發送過去的url將被解析爲: http://myserver/search.jsp?value=123&;JSESSIONID=16CD67F723A6D2218CE73AEAEA899FD9

 

 7 webInject的不足

1 不支持中文
2 異常處理不好(config.xml中配置錯誤路徑的testcase.xml,run gui後界面無反應)
3 不執行response中的腳本.(javascript,vbscript等)
4 不支持http 重定向

 

 

 
發佈了34 篇原創文章 · 獲贊 0 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章