(十一)檢查點

一、什麼是檢查點

  • 檢查點的功能主要驗證某個界面上是否存在指定的Text或Image等對象
  • 在使用LoadRunner測試Web應用時,可以檢查壓力較大時Web服務器能否返回正常的頁面
  • 與QTP設置的檢查點還不同,QTP是檢查一個對象的某個屬性是否正確,LoadRunner是檢查響應是否正確

二、檢查點函數:web_find
Return Values:
This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

添加步驟:

  • 錄製過程中添加的檢查點時web_reg_find,測試點要加在事務中,所以要在錄製結束後添加該函數的檢查點。
  • 手動登錄系統,將要作爲檢查點的文本複製下來
  • 添加檢查點的位置,就是客戶端發送一個請求,服務器響應的個頁面(但我們不知道這個頁面是否正確),所以要在該請求函數的下面加檢查點函數。光標焦點在要插入檢查點位置,Insert—>Add Step—>Web Check—>Text Check 在網頁中將要檢查的文本複製到這裏即可
  • web_find和web_image_check函數在回放中執行,還要在Eidit Runtime Setting—>Internet Protocol—>Preferences–>Check 選中”Enable Image and Text check”
int a=-1;
..........

    a=web_find("web_find",
        "What=Welcome, jojo, to the Web ",
        LAST);
    if (a==0) 
      {
        lr_log_message("login succeed.......");
       }
     else
     {
         lr_log_message("login fail.......");
     }

該函數有返回值,在C語言中,變量要先定義後使用,注意變量定義,要在Action、vuser_int、vuser_end最開始的位置定義,否則有語法錯誤。

  • web_find已經過時,更多是用web_reg_find,過時原因是其執行時間長
    兩者的區別是:web_reg_find先註冊,後查找;
The web_reg_find function registers a request to search for a text string on a Web page retrieved by the next action function, such as web_url. 
也就是說放在請求的前面

web_find查找前面請求的結果

The web_find function searches an HTML page for a specified text string. web_find is deprecated. It has been replaced with web_reg_find. 

放在請求的後面

三、web_image_check

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

Alt:替換文本屬性。
①用來爲圖像定義一串預備的可替換的文本。替換文本屬性的值是用戶定義的。
②在瀏覽器無法載入圖片時,替換文本屬性告訴讀者他們失去的信息。此時,瀏覽器將顯示這個替換性的文本而不是圖片。
Scr:源屬性
源屬性的值是該圖片的URL地址,即圖片存放位置。

    web_image_check("web_image_check",
        "Src=images/webtours.png",
        LAST);

步驟:
- 錄製過程中添加的檢查點時web_reg_find,測試點要加在事務中,所以要在錄製結束後添加該函數的檢查點。
- 手動登錄系統,因爲LoadRunner中沒有spy,①要獲取該圖片的名稱,右擊圖片—->圖片另存爲。②右擊圖片—>查看源文件③快速搜索到該圖片,則編輯—>查找
- 添加檢查點的位置,就是客戶端發送一個請求,服務器響應的個頁面(但我們不知道這個頁面是否正確),所以要在該請求函數的下面加檢查點函數。光標焦點在要插入檢查點位置,Insert—>Add Step—>Web Check—>Image_check
- web_find和web_image_check函數在回放中執行,還要在Eidit Runtime Setting—>Internet Protocol—>Preferences–>Check 選中”Enable Image and Text check”

四、web_reg_find
LoadRunner中,帶有reg字樣的函數,稱爲註冊性函數,該類函數的特點就是要將函數寫在相應請求之前
若錄製過程中,忘記加web_reg_find檢查點,則可以再添加:
- 手動登錄系統,注意不能像web_find那樣直接在網頁中複製內容,要在源文件中,找到並複製(因爲它是帶格式的檢查,比如字體加粗、顏色等)
- 添加檢查點的位置,就是客戶端發送一個請求,服務器響應的個頁面(但我們不知道這個頁面是否正確),所以要在該請求函數的下面加檢查點函數。光標焦點在要插入檢查點位置,Insert—>Add Step—>Services—>web_reg_find

//web lr函數變量在函數中直接使用,不必提前定義
web_reg_find("Text=ABC", "SaveCount=abc_count", LAST ); 
//請求前
web_url("Step", "URL=...", LAST ); //請求
//請求後即應答。查看檢查點文本出現的次數,要放在請求後,
//因爲請求前寫的只是註冊,並沒有得到該頁面信息,沒法檢查
if (strcmp(lr_eval_string("{abc_count}"), "0") == 0) 

    lr_output_message("not found");

else 

 lr_output_message("%s times",lr_eval_string("{abc_count}"));
//%s:是格式控制  說明要輸出的是字符串

SaveCount參數
- SaveCount=param:The number of matches that were found, stored in a parameter. 找到的匹配的個數,並將該值存儲在參數param中
- When the SaveCount argument is used, and the Fail argument is not used, the check does not fail whether the text is found or not. To check whether the text has been found, examine the value of the SaveCount parameter. If it is “0”, the string was not found.
當SaveCount參數使用,Fail參數未使用時,那麼無論文本是否找到,檢查點不會失敗。這時判斷文本是否找到,則要檢查SaveCount的值,如果是0,則未找到。
- If both SaveCount and Fail are used, the Fail handling option specified works together with the SaveCount. Thus, if SaveCount is used with “Fail=NotFound” and the text is found, the SaveCount parameter is assigned the number of occurrences and the check succeeds. If the text is not found, the SaveCount parameter is assigned “0” and the check fails. Of course, if the text is not found and “Fail=NotFound” has been specified, the value “0” of the parameter is only useful if the run–time setting Continue on error is selected.
若SaveCount和Fail參數共同使用,則失敗處理和SaveCount共同工作。因此,若SaveCount和”Fail=NotFound”一起使用,文本找到,則SaveCount參數就是出現的次數並且檢查點成功;拖文本沒有找到,SaveCount=0,檢查失敗,參數爲0有用,只有在run-time setting中”Continue on error”備選情況下
- The value assigned to the parameter is retained between iterations until the first action function following the web_reg_find of the next iteration. Once the script perfoms the first action function following the web_reg_find of the next iteration, the count is updated. Alternatively, you can use the lr_save_string function to change the value of the parameter at the end of the current interation—for example, with lr_save_string(“0”, “Count”).

lr_eval_string:
取出lr、web函數中定義的變量值,可以用該函數。
The lr_eval_string function returns the input string after evaluating any embedded parameters. If the string argument contains only a parameter, the function returns the current value of the parameter.
當參數只有一個時,則返回該參數。

lr_output_message

int lr_output_message( const char *format, exp1, exp2,...expn.); 
參考C語言中printf(格式控制,輸出列表);
printf("%d,%d,%d",10,11,12);

search參數
Search: The scope of the search—where to search for the string. The possible values are Headers (search only the headers), Body (search only the Body data), Noresource (search only the HTML body, excluding headers and resources), or ALL (search body , headers, and resources). The default value is BODY.

****** Response Header For Transaction With Id 7 ******
HTTP/1.1 200 Ok
Server: Xitami
Date: Mon, 09 Jul 2018 10:11:18 GMT
Content-type: text/html
Content-length: 692
Last-modified: Tue, 08 May 2007 11:40:24 GMT


$$$$$$ Response Header For Transaction With Id 7 Ended $$$$$$

****** Response Body For Transaction With Id 7 ******
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD></HEAD>
<BODY bgcolor=#003366 leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td align="left" valign="middle" width="50%"><img src="images/hp_logo.png" alt="" height="45" width="69" align="absmiddle" border="0"><img src="images/webtours.png" alt="" height="45" width="130" align="absmiddle" border="0"></td>
                <td align="right"></td>
                <td></td>
            </tr>
        </table>
    </BODY>

$$$$$$ Response Body For Transaction With Id 7 Ended $$$$$$

四、當回放時,在replay log 中記錄了腳本中每行執行情況,因爲後添加了檢查點函數,希望能夠快速看到該行執行情況,可以點擊腳本中該行,在VuG軟件的右下角有Col=xx Line=xx,當確定行數後,就可以在在replay log中找Action.c(行數)了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章