loadRunner函數之web_find


int  web_find( const char * StepName, < Attributes and Specifications list>, char * searchstring, LAST ); 
 
StepName:步驟名稱,必選
Attributes and Specifications list:屬性列表,可選
    expect:定義返回成功的標准,found(默認)-表示找到字符串返回成功,notfound-表示未找到字符串返回成功
    Matchcase:是否區分大小寫,yes-表示區分大小寫,no(默認)-表示不區分大小寫
    report:定義結果報告的內容,success-只包含成功,failure-只包含失敗,always(默認)-包含所有
    onfailure=abort:失敗則終止腳本運行
    RightOf:從指定字符串的右邊開始查找
    LeftOf:從指定字符串的左邊開始查找
searchstring:查找的字符串,格式為:"What=stringxyz",必選
LAST:結束標記,必選
 
 

WebTours登錄后頁面展示的內容:

Welcome, jojo, to the Web Tours reservation pages.
Using the menu to the left, you can search for new flights to book, or review/edit the flights already booked. Don't forget to sign off when you're done!
 
 
1、web_find之expect屬性:
Action() 
{ 

    web_url("WebTours", 
        "URL=http://127.0.0.1:1080/WebTours/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t34.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=../favicon.ico", "Referer=", ENDITEM, 
        LAST); 

    web_submit_form("login.pl", 
        "Snapshot=t35.inf", 
        ITEMDATA, 
        "Name=username", "Value=jojo", ENDITEM, 
        "Name=password", "Value=bean", ENDITEM, 
        "Name=login.x", "Value=52", ENDITEM, 
        "Name=login.y", "Value=11", ENDITEM, 
        LAST); 

    web_find("web_find", 
        //期望返回成功的結果是找到字符串,因當前頁面包含要查找的字符串,故返回結果是成功 
        "expect=found", 
        //當前頁面中查找字符串"jojo" 
        "What=jojo", 
        LAST); 

    web_find("web_find", 
        //期望返回成功的結果是未找到字符串,因當前頁面包含要查找的字符串,故返回結果是失敗
        "expect=notfound", 
        //當前頁面中查找字符串"jojo" 
        "What=jojo", 
        LAST); 

    return 0; 
} 

 

代碼執行結果:

Action.c(24): "web_find" successful. 1 occurrence(s) of "jojo" found (RightOf="", LeftOf="")   [MsgId: MMSG-27196] 

Action.c(24): web_find was successful   [MsgId: MMSG-26392]

Action.c(31): Error -27195: "web_find" failed. 1 occurrence(s) of "jojo" found (RightOf="", LeftOf="")   [MsgId: MERR-27195]

Action.c(31): web_find highest severity level was "ERROR"   [MsgId: MMSG-26391]

 
 
2、web_find之Matchcase屬性:
Action() 
{ 

    web_url("WebTours", 
        "URL=http://127.0.0.1:1080/WebTours/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t34.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=../favicon.ico", "Referer=", ENDITEM, 
        LAST); 

    web_submit_form("login.pl", 
        "Snapshot=t35.inf", 
        ITEMDATA, 
        "Name=username", "Value=jojo", ENDITEM, 
        "Name=password", "Value=bean", ENDITEM, 
        "Name=login.x", "Value=52", ENDITEM, 
        "Name=login.y", "Value=11", ENDITEM, 
        LAST); 

    web_find("web_find", 
        //區分大小寫,因當前頁面不包含JOJO,故返回結果是失敗
        "Matchcase=yes", 
        //當前頁面中查找字符串"JOJO" 
        "What=JOJO", 
        LAST); 

    web_find("web_find", 
        //不區分大小寫,因當前頁面包含jojo,故返回結果是成功
        "Matchcase=no", 
        //當前頁面中查找字符串"JOJO" 
        "What=JOJO", 
        LAST); 

    return 0; 
}  

 


代碼執行結果:
Action.c(24):  Continuing after Error -27195: "web_find" failed. 0 occurrence(s) of "JOJO" found (RightOf="", LeftOf="")   [MsgId: MERR-27195]
Action.c(24):  web_find highest severity level was "continue on error"   [MsgId: MMSG-26391]
Action.c(24):  Continuing after error in Vuser script.
Action.c(31):  "web_find" successful. 1 occurrence(s) of "JOJO" found (RightOf="", LeftOf="")    [MsgId: MMSG-27196]
Action.c(31):  web_find was successful   [MsgId: MMSG-26392]
 
 
3、web_find之onfailure屬性:
Action() 
{ 

    web_url("WebTours", 
        "URL=http://127.0.0.1:1080/WebTours/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t34.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=../favicon.ico", "Referer=", ENDITEM, 
        LAST); 

    web_submit_form("login.pl", 
        "Snapshot=t35.inf", 
        ITEMDATA, 
        "Name=username", "Value=jojo", ENDITEM, 
        "Name=password", "Value=bean", ENDITEM, 
        "Name=login.x", "Value=52", ENDITEM, 
        "Name=login.y", "Value=11", ENDITEM, 
        LAST); 

    web_find("web_find", 
        //如果函數返回結果失敗,則終止腳本運行,根據運行結果可以發現,第二個web_find沒有運行
        //注意:Continue on Error 設置了才能看到效果,否則的話,不管是否有該屬性都會終止運行
        "onfailure=abort", 
        //當前頁面中查找字符串"JOJO" 
        "What=jojo1", 
        LAST); 

    web_find("web_find", 
        //當前頁面中查找字符串"JOJO" 
        "What=jojo", 
        LAST); 

    return 0; 
}  
 
代碼運行結果:
Action.c(24):  Fatal Error -27195: "web_find" failed. 0 occurrence(s) of "jojo1" found (RightOf="", LeftOf="")    [MsgId: MERR-27195]
Action.c(24):  web_find highest severity level was "FATAL ERROR"   [MsgId: MMSG-26391]
Abort was called from an action.
 
 
4、web_find之LeftOf、RightOf屬性:
Action() 
{ 

    web_url("WebTours", 
        "URL=http://127.0.0.1:1080/WebTours/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t34.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=../favicon.ico", "Referer=", ENDITEM, 
        LAST); 

    web_submit_form("login.pl", 
        "Snapshot=t35.inf", 
        ITEMDATA, 
        "Name=username", "Value=jojo", ENDITEM, 
        "Name=password", "Value=bean", ENDITEM, 
        "Name=login.x", "Value=52", ENDITEM, 
        "Name=login.y", "Value=11", ENDITEM, 
        LAST); 

    web_find("web_find", 
        //從, to the Web左邊查找jojo
        "LeftOf=, to the Web", 
        //從Welcome右邊查找jojo
        "RightOf=Welcome, ", 
        "What=jojo", 
        LAST); 

    return 0; 
} 

代碼運行結果:
Action.c(24):  "web_find" successful. 1 occurrence(s) of "jojo" found (RightOf="Welcome, ", LeftOf=", to the Web")   [MsgId: MMSG-27196]
Action.c(24):  web_find was successful   [MsgId: MMSG-26392]


免責聲明!

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



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