脚本编写一:检查点函数web_reg_find

在loadrunner中可以添加检查点,以检查从服务器返回的内容是否正确。

对应的函数是:

      Image Check:web_image_check

      Text Check:web_find 和web_reg_find

一:web_reg_find 和web_find的区别

二:web_reg_find 只要用法

1.函数定义

该函数的作用是“在缓存中查找相应的内容”,常用参数及含义如下:

web_reg_find("Search=Body", //定义查找范围
"SaveCount=ddd", //定义查找计数变量名称
"Text=aaaa", //定义查找内容

LAST);

2.使用该函数注意以下事项:

1)该函数写在要查找内容的请求之前,通常情况下写在如下六个函数之前:
Web_castom_request();
web_image();

web_link();

web_submit_data();

web_submit_form();

web_url()

2)在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到,下面举个例子来说明:(实际测试中的例子)

Action()
{

/* Request with GET method to URL "http://10.17.17.37:9092/favicon.ico" failed during recording. Server response : 404*/

    web_custom_request("login",
        "URL=http://10.17.17.37:8082/SNDSys/rest/user/login",
        "Method=OPTIONS",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Mode=HTML",
        LAST);

    web_reg_find("Fail=NotFound",
        "Search=All",
        "SaveCount=login_count",
        "Text=\"userid\":\"dj\"",
        LAST);

    web_custom_request("login_2",
        "URL=http://10.17.17.37:8082/SNDSys/rest/user/login",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "RecContentType=application/json",
        "Referer=http://10.17.17.37:9092/snd/",
        "Snapshot=t6.inf",
        "Mode=HTML",
        "EncType=application/json;charset=utf-8",
        "Body={\"userid\":\"dj\",\"password\":\"e10adc3949ba59abbe56e057f20f883e\"}",
        LAST);

    //if(strcmp(lr_eval_string("{Count}"),"0")==0)
    if(strcmp(lr_eval_string("{Count}"))>0)
    lr_log_message("登陆失败!");
    else
    lr_log_message("登陆成功!");


return 0;
}

3.插入函数的方法

1)手工写入,在需要插入函数的位置手工写入该函数;
2)光标停留在要插入函数的位置,在INSERT菜单中,选择new step,在列表中选择或查找要插入的函数,根据提示填写必要的参数;
3)在tree view模式下,选中要检查的页面,切换到HTTP View模式下,选择Raw Data在Response中找到要检查的文本,右键点击“Add  Text Check Step”就可以增加检查点了。
对代码不熟悉建议在树形结构中添加检查点

猜你喜欢

转载自blog.csdn.net/qq_39247153/article/details/82856953