Loadrunner關於頁面檢查的幾個函數詳解


環境:
Loadrunner版本:8.0
自建一個test.html文件:
<html>
<head>
<meta name="google1" content="google2"/>
<title>google3</title></head>
<body>
google4:<input type="text" name="google5" />
<input type="submit" value="google6"/><br>
<a href="http://www.google.com/calendar/render?hl=zh-CN&tab=wc" class="gb2">google7</a><br>
<img src=http://www.google.cn/intl/zh-CN/images/logo_cn.gif width=200 height=88 border=0 alt="google8" title="Google9">
<img src=http://www.google.cn/intl/zh-CN/images/logo_cn.gif width=200 height=88 border=0 alt="google8" title="Google9">
</body>
</html>
 
一、web_image_check

語法:
int web_image_check(const char*CheckName,<List of Attributes>,<"Alt=alt"|| "Src=src">, LAST );

 

參數:

1、CheckName:Check名稱。
2、List of Attributes:
支持的屬性有:Frame(在多Frame的情況下,定義要查找Frame的范圍)。
支持的選項有:
Expect:檢查通過的條件,默認為Found
Matchcase:是否區分大小寫,默認為no
Repeat:找到第一個符合條件字符串后,是否還繼續搜索,默認為yes
Report:什么情況下(success、failure、always)顯示檢查結果,默認always
Onfailure:失敗(expect的值決定)的情況下,是否繼續,默認為Continue on Error。
3、Alt:圖片的ALT標記。
4、Src:圖片的SRC標記。

說明:

1、注意勾上Runtime Settings—Internet Protocl—Preferences—Checks:Enable Image and text check
2、注意該函數放到web_url后面,且Web_url的Mode須為html(此函數僅僅支持基於HTML的腳本)
3、Web_image_check檢查指定的圖象是否在HTML頁面中出現。
4、Alt或者Src兩者必須有一個在參數列表中出現。如果兩項都通過,那么檢查成功。

 

示例:
Loadrunner腳本:

……
 web_url("google",
  "URL=http://127.0.0.1:8000/test.html",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTML",
  LAST);

 

 web_image_check("web_image_check",
  "expect=NotFound",
  "Alt=Google8",
  "matchcase=no",
  "repeat=no",
  "report=failure",
  "Onfailure=abort",
  LAST);

 web_find("web_find",
  "What=Google",
  LAST);
……

運行結果:

Starting action Action.
Action.c(15): Found resource "http://www.google.cn/intl/zh-CN/images/logo_cn.gif" in HTML "http://127.0.0.1:8000/test.html"   [MsgId: MMSG-26659]
Action.c(15): web_url("google") was successful, 11968 body bytes, 521 header bytes   [MsgId: MMSG-26386]
Action.c(35): Fatal Error -27191: "web_image_check" failed (1 occurrence(s) found. Alt="Google8", Src="")   [MsgId: MERR-27191]
Action.c(35): web_image_check highest severity level was "FATAL ERROR"   [MsgId: MMSG-26391]
Abort was called from an action.
Ending Vuser...

 

解釋:

1、 expect=NotFound,由於找到了符合要求的結果,所以為失敗
2、 repeat=no,實際上有兩個符合條件的結果,不過不繼續,所以1 occurrence(s) found
3、 Onfailure=abort,該檢查結果為fail,所以abort,后面的文件檢查未執行。

 

二、web_find

 

語法:
 int web_find (const char*StepName, <Attributes and Specifications list>,char*searchstring, LAST );

 

參數:

1、StepName:Check名稱
2、Attributes and Specifications list:
支持的屬性有:
Expect:定義在什么情況下函數檢查成功:找到了指定的搜索標准或者沒有找到。例如說,可以檢查指定的錯誤信息是否出現在web頁面中。合法的值有2個:found和notfound。默認值是“found”。

 

Matchcase:指定搜索是否區分大小寫,默認為no。

 

Repeat:指定當第一次發現要查找的字符串時,搜索是否繼續。當一個web頁面中包含多個被查找的字符串時,此參數是非常有用的。合法的值有2個:yes,no。默認值是“yes”。

Report:指定在什么情況下,VuGen在執行日志中顯示此函數的檢查結果。合法的值有:success,failure,always。默認值是“always”。

 

Onfailure:此參數決定在函數檢查失敗后,Vuser是否中斷。參數值是abort。如果指定了Onfailure=abort,當函數檢查失敗時,不論在運行時設置中的error-handling(Runtime Settings—Miscellaneous)是什么,腳本都會中斷。如果沒有指定Onfailure=abort,那么運行時設置中error-handling將會起作用。

 

支持的特性有:RightOf, LeftOf (不支持7.x及更高版本)。

 

RightOf:要查找的字符串右邊的內容。

 

LeftOf:要查找的字符串左邊的內容。

 

3、Searchstring:需要查找的字符串,格式為“What=stringxyz”。此搜索不區分大小寫。

 

4、LAST:屬性列表結束符。

說明:

1、注意勾上Runtime Settings—Internet Protocl—Preferences—Checks:Enable Image and text check
2、注意該函數放到web_url后面,且Web_url的Mode須為html
3、此函數的作用是在HTML頁面中查找指定的字符串。
4、函數只能在基於HTML錄制的腳本中使用。當指定的HTML請求全部完成以后,開始執行搜索過程,比web_reg_find要慢。
5、web_find函數在C語言的腳本中已經被web_reg_find所替代,web_reg_find運行速度比較快,而且在HTML-based和URL-based的錄制方式中都可以使用。
6、在C語言腳本中,web_find是向后兼容的。Java和Visual Basic腳本中不支持它。
7、WAP和WSP協議不支持。

 

示例:
Loadrunner腳本:

……
 web_reg_find("Text/IC=google",
    "Search=Body",
  LAST);

 

 web_url("google",
  "URL=http://127.0.0.1:8000/test.html",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTML",
  LAST); 

 

 web_find("web_find",
  "What=Google",
  LAST);
……

運行結果:

Starting action Action.
Action.c(7): Registering web_reg_find was successful   [MsgId: MMSG-26390]
Action.c(15): Found resource "http://www.google.cn/intl/zh-CN/images/logo_cn.gif" in HTML "http://127.0.0.1:8000/test.html"   [MsgId: MMSG-26659]
Action.c(15): Registered web_reg_find successful for "Text=google" (count=14)   [MsgId: MMSG-26364]
Action.c(15): web_url("google") was successful, 11968 body bytes, 521 header bytes   [MsgId: MMSG-26386]
Action.c(44): "web_find" successful. 3 occurrence(s) of "Google" found (RightOf="", LeftOf="")   [MsgId: MMSG-27196]
Action.c(44): web_find was successful   [MsgId: MMSG-26392]
Ending action Action.

 

解釋:

可以看出兩個函數最后的檢索結果不一樣,web_reg_find發現了14個,web_find只發現了3個。這是在web_find里再添加一個屬性—"matchcase=yes",運行結果為:
Action.c(44): Error -27195: "web_find" failed. 0 occurrence(s) of "Google" found (RightOf="", LeftOf="")   [MsgId: MERR-27195]
Action.c(44): web_find highest severity level was "ERROR"   [MsgId: MMSG-26391]
web_find只檢索“>”、“<”間的內容。

三、web_reg_find

 

語法: int web_reg_find (const char*attribute_list, LAST);

 

參數:

1、attribute_list:
通過Name=Value對來傳遞參數。例如“Text=string”。Text,TextPfx,TextSfx三個必須有一個出現。其他的屬性是可選的。

 

Text:要搜索的字符串,字符串必須非空,以NULL結尾。可以使用text flags自定義搜索字符串。

 

TextPfx:要搜索的字符串的直接前綴。

TextSfx:要搜索的字符串的直接后綴。

 

Search:搜索的范圍。可選的值是:Headers(search only the headers) 、Body(search only the Body data)、Noresource (search only the HTML body, excluding headers and resources)、ALL (search body , headers, and resources),默認值是“BODY”。

SaveCount:保存到參數中的匹配的字符串的個數。使用這個屬性,需要指定“SaveCount=param”。檢查操作被執行后,param 的值是null結尾的數字類型的值。

 

Fail:設置函數檢查在什么狀態下失敗。可以是“Found或“NotFound”。默認是“NotFound”。

 

ID:日志文件中標識此函數的一個字符串。

RelFrameId:相關聯的FrameId。注意:此參數在GUI級別的腳本中不受支持。

 

2、LAST:屬性列表結束的標記符。

 

說明:

1、web_reg_find屬於注冊函數,注冊一個在web頁面中搜索文本字符串的請求,在接下來Action(象web_url)類函數中執行搜索。

 

2、通過查找期望的字符是否存在來驗證是否返回了期望的頁面。例如,通過查找“Welcome”來檢查主頁是否完全打開了。也可以查找“Error”檢查瀏覽器是否發生錯誤。還可以使用此函數注冊一個請求來統計特定字符串出現的次數。

 

如果檢查失敗,在接下來的Action類的函數中會報告錯誤。此函數僅僅注冊請求,並不執行。函數的返回值只表明注冊是否成功,並不表示檢查的結果。

 

3、此函數不僅能夠查找text,還能查找到圍繞着text的strings。不要同時指定text和前綴后綴。

4、此函數在HTML-based和URL-based的腳本中都可以使用。此函數是在所請求內容到達之前注冊搜索請求的,所以當所請求內容一到達后就會執行搜索,產生的腳本比較高效。

示例:
Loadrunner腳本:

……
 web_reg_find ("Text/IC=google",
    "Search=Body",
  LAST);

 web_url("google",
  "URL=http://127.0.0.1:8000/test.html",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode= HTTP ",
  LAST); 

 web_url("google",
  "URL=http://www.baidu.com/",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTTP",
  LAST);
……

運行結果:

Starting action Action.
Action.c(7): Registering web_reg_find was successful   [MsgId: MMSG-26390]
Action.c(12): Registered web_reg_find successful for "Text=google" (count=14)   [MsgId: MMSG-26364]
Action.c(12): web_url("google") was successful, 538 body bytes, 295 header bytes   [MsgId: MMSG-26386]
Action.c(22): web_url("google") was successful, 1714 body bytes, 372 header bytes   [MsgId: MMSG-26386]
Ending action Action.

 

解釋:

由上面的結果可以看出,web_reg_find 只在其之后的一個Action類函數中執行搜索。

 

四、web_global_verification

語法:
 int web_global_verification(<List of Attributes>, LAST );

參數:
List of Attributes:

 

Text:此屬性是一個非空的,以NULL結尾的字符串,表示要查找的內容。語法是”Text=string”。還可以使用text flags自定義字符串。

 

TextPfx:沒有指定Text的情況下使用此屬性。要查找的字符串的前綴。語法是” TextPfx =string”。還可以使用text flags自定義字符串。

TextSfx:沒有指定Text的情況下使用此屬性。要查找的字符串的后綴。語法是” TextSfx =string”。還可以使用text flags自定義字符串。

Search:可選項,在哪里查找字符串。可選的值是:Headers,Body,NORESOURCE或All。默認值是NORESOURCE。語法是“Search=value”。

 

Fail:當字符串找不到時的處理選項:Found (默認值)或NotFound。Found表示當找到對應的字符串時發生了錯誤(例如“Error”)。NotFound表示當找不到字符串時發生了錯誤。語法是“Fail=value“。

 

ID:在日志文件中標識當前函數。

注:text flags:/IC表示忽略大小寫;/BIN表示指定的是二進制數據。

說明:

web_global_verification屬於注冊函數,注冊一個在web頁面中搜索文本字符串的請求,與web_reg_find只在下一個Action函數中執行搜索不同的是,它是在之后所有的Action類函數中執行搜索的。可以搜索頁面的body,headers,html代碼或者是整個頁面。

 

在檢測一些應用程序級別(不通過http狀態碼來表現)的錯誤時,web_global_verification是非常有用的。如果要定位通過HTTP狀態碼表現的錯誤時,使用web_get_int_property。

 

查找范圍:all:這個HTML頁面;Headers:頁面的頭;body:頁面的體,包含所有的資源但不包含頭;NORESOURCE(默認選項):僅僅包含頁面的體,把包括頭和資源。

 

如果不知道要查找的精確的文本,或者要查找的多個文本不是完全相同的,可以使用前綴和后綴來表示。這時需要用到TextPfx和TextSfx屬性。這2個屬性必須同時指定,一旦指定了其中一個,就不能指定Text屬性了。

 

注意:web_global_verification在WAP協議下不能運行。

 

示例:
Loadrunner腳本:

……
 web_global_verification("Text/IC=google",
  "Fail=NotFound",
   LAST);

 

 web_url("google",
  "URL=http://127.0.0.1:8000/test.html",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode= HTTP ",
  LAST); 

 web_url("google",
  "URL=http://www.baidu.com/",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTTP",
  LAST);
……

運行結果:

 

Starting action Action.
Action.c(7): Registering web_global_verification was successful   [MsgId: MMSG-26390]
Action.c(11): web_url("google") was successful, 538 body bytes, 295 header bytes   [MsgId: MMSG-26386]
Action.c(21): Error -26366: "Text=google" not found for web_global_verification   [MsgId: MERR-26366]
Action.c(21): web_url("google") highest severity level was "ERROR", 1714 body bytes, 372 header bytes   [MsgId: MMSG-26388]
Ending action Action.

解釋:
由上面的結果可以看出,web_global_verification在其之后所有的Action類函數中執行搜索。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM