(十一)检查点

一、什么是检查点

  • 检查点的功能主要验证某个界面上是否存在指定的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(行数)了

猜你喜欢

转载自blog.csdn.net/jiangshangchunjiezi/article/details/80981311