LoadRunner检查点

admin 2018-09-16 阅读


1:一般的文本类型检查点

web_reg_find("Text=Welcome, <b>admin", LAST);

//检查下面的页面是否有 Text文本类型的文字 Welcome,admin;

Action()
{

	web_url("picinfo.ini", 
		"URL=http://se.360.cn/cloud/picinfo.ini", 
		"TargetFrame=", 
		"Resource=1", 
		"RecContentType=application/octet-stream", 
		"Referer=", 
		"Snapshot=t1.inf", 
		LAST);

	web_add_cookie("MUID=3B882A344D5C68BB06CB2651495C6958; DOMAIN=www.bing.com");

	//关联 关联session
	web_reg_save_param("sessionID",
		"LB=value=",
		"RB=>",
		LAST);


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

	//检查点 检查登陆后页面是否有 Welcome,admin这段文本文字出现
	web_reg_find("Text=Welcome, <b>admin", LAST);

	lr_think_time(12);

	web_submit_data("login.pl", 
		"Action=http://127.0.0.1:1080/WebTours/login.pl", 
		"Method=POST", 
		"TargetFrame=body", 
		"RecContentType=text/html", 
		"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
		"Snapshot=t3.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=userSession", "Value={sessionID}", ENDITEM, //使用上一次关联的动态session
		"Name=username", "Value=admin", ENDITEM, 
		"Name=password", "Value=123456", ENDITEM, 
		"Name=JSFormSubmit", "Value=off", ENDITEM, 
		"Name=login.x", "Value=60", ENDITEM, 
		"Name=login.y", "Value=10", ENDITEM, 
		LAST);

	return 0;
}

2:文本类增强型检查点(可以判断参数)

如下 代码:

//检查点 检查登陆后页面是否有 Welcome,admin这段文本文字出现 并统计该文本在下一个action出现次数,普通的加查点 该检查点增加"SaveCount=textCount" SaveCount是固定的 textCount是变量名可以随便命名。

web_reg_find("Text=Welcome, <b>admin", "SaveCount=textCount",LAST);

//下面是一个逻辑判断 即如果统计出来的welcome,admin次数大于0则输出“====login success======”,否则输出"======login fail======"

    //验证是否找到了页面上的要检查的字符串 atoi将字符型转换成int
    if (atoi(lr_eval_string("{textCount}"))>0) {
        lr_output_message("====login success======");
    }
     else{
      lr_output_message("======login fail======");
    }

Action()
{

	web_url("picinfo.ini", 
		"URL=http://se.360.cn/cloud/picinfo.ini", 
		"TargetFrame=", 
		"Resource=1", 
		"RecContentType=application/octet-stream", 
		"Referer=", 
		"Snapshot=t1.inf", 
		LAST);

	web_add_cookie("MUID=3B882A344D5C68BB06CB2651495C6958; DOMAIN=www.bing.com");

	//关联 关联session
	web_reg_save_param("sessionID",
		"LB=value=",
		"RB=>",
		LAST);


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

	//检查点 检查登陆后页面是否有 Welcome,admin这段文本文字出现 并统计该文本在下一个action出现次数
	web_reg_find("Text=Welcome, <b>admin", "SaveCount=textCount",LAST);

	lr_think_time(12);

	web_submit_data("login.pl", 
		"Action=http://127.0.0.1:1080/WebTours/login.pl", 
		"Method=POST", 
		"TargetFrame=body", 
		"RecContentType=text/html", 
		"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
		"Snapshot=t3.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=userSession", "Value={sessionID}", ENDITEM, //使用上一次关联的动态session
		"Name=username", "Value=admin", ENDITEM, 
		"Name=password", "Value=123456", ENDITEM, 
		"Name=JSFormSubmit", "Value=off", ENDITEM, 
		"Name=login.x", "Value=60", ENDITEM, 
		"Name=login.y", "Value=10", ENDITEM, 
		LAST);

	//验证是否找到了页面上的要检查的字符串 atoi将字符型转换成int
	if (atoi(lr_eval_string("{textCount}"))>0) {
		lr_output_message("====login success======");
	}
	 else{
	  lr_output_message("======login fail======");
	}

	return 0;
}

3:图片检查点

代码如下:

注意:图片型检查点与reg(注册型)检查点的区别:图片型检查点写在被检查函数后面 注册型检查点写在被检查函数前面

Action()
{

	web_url("picinfo.ini", 
		"URL=http://se.360.cn/cloud/picinfo.ini", 
		"TargetFrame=", 
		"Resource=1", 
		"RecContentType=application/octet-stream", 
		"Referer=", 
		"Snapshot=t1.inf", 
		LAST);

	web_add_cookie("MUID=3B882A344D5C68BB06CB2651495C6958; DOMAIN=www.bing.com");

	//关联 关联session
	web_reg_save_param("sessionID",
		"LB=value=",
		"RB=>",
		LAST);


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

	//检查点 检查登陆后页面是否有 Welcome,admin这段文本文字出现 并统计该文本在下一个action出现次数
	web_reg_find("Text=Welcome, <b>admin", "SaveCount=textCount",LAST);

	lr_think_time(12);

	web_submit_data("login.pl", 
		"Action=http://127.0.0.1:1080/WebTours/login.pl", 
		"Method=POST", 
		"TargetFrame=body", 
		"RecContentType=text/html", 
		"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
		"Snapshot=t3.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=userSession", "Value={sessionID}", ENDITEM, //使用上一次关联的动态session
		"Name=username", "Value=admin", ENDITEM, 
		"Name=password", "Value=123456", ENDITEM, 
		"Name=JSFormSubmit", "Value=off", ENDITEM, 
		"Name=login.x", "Value=60", ENDITEM, 
		"Name=login.y", "Value=10", ENDITEM, 
		LAST);

	//图片型检查点,需要卸载被检查函数后面
	web_image_check("web_image_check","src=/WebTours/images/signoff.gif",LAST);

	return 0;
}

PS:需要在LoadRunner运行时设置中打开"Enable Image and text check" 否则不会执行这个图片检查点

来源:未知

声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。