web_reg_find是先注册(register)后查找的;使用时将它放在请求语句的前面。 而web_find是查找前面的请求结果;使用时将它放在请求语句的后面。
另二者的参数也完成不一样的,web_reg_find参数中SaveCount记录查找匹配的次数, web_find的机制是一旦查找匹配成功就立即返回,并不继续查找和记录匹配次数
再者Run-time设置中的“enable image and text check”对web_find有效,而对web_reg_find无效。 注意:web_find不支持URL模式下录制的脚本。
另,LR自身已经提供了关于Page title的检查点的设置。路径: Recording setting >Advanced.
脚本示例:
同样的script, 如果添加web_reg_find,事务运行结果失败:
Action.c(50): Error -26366: "Text=Dashboard" not found for web_reg_find [MsgId: MERR-26366]
Action.c(50): web_submit_form("wp-login.php_2") highest severity level was "ERROR", 39882 body bytes, 3207 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26387]
Action.c(50): Notify: Transaction "Login_WordPress" ended with "Fail" status (Duration: 5.9267 Wasted Time: 0.0000).
Ending action Action.
Ending iteration 2.
而如果没有同,整个事务,包括 action运行成功:
Action.c(110): web_url("index-extra.php_5") was successful, 1047 body bytes, 2682 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26385]
Action.c(124): Log on successfully
Ending action Action.
Ending iteration 2.
Action()
{
int status; //定义变量,用于判断登陆是否成功
// web_add_cookie("rtime=1; DOMAIN=bjdns2.cncmax.cn");
//
// web_add_cookie("ltime=1303876351121; DOMAIN=bjdns2.cncmax.cn");
//
// web_add_cookie("cnzz_eid=64563578-1302487037-http://bjdns2.cncmax.cn:8080/?HOST=home.beyondsoft.com&R=/& DOMAIN=bjdns2.cncmax.cn");
//
// web_add_cookie("JSESSIONID=E73D3BF7B18442F72B93F5EF37B5E545; DOMAIN=bjdns2.cncmax.cn");
web_url("bjdns2.cncmax.cn:8080",
"URL=http://bjdns2.cncmax.cn:8080/?HOST=wpad.beyondsoft.com&R=/wpad.dat&",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
// web_add_cookie("wp-settings-time-1=1304042778; DOMAIN=demo.opensourcecms.com");
//
// web_add_cookie("wordpress_test_cookie=WP+Cookie+check; DOMAIN=demo.opensourcecms.com");
//
// web_add_cookie("wordpress_logged_in_613541581fd3dd54ee5153849996d0f6=admin|1304215578|8148fb498981bf15c2f239b9d3dbdf5d; DOMAIN=demo.opensourcecms.com");
//
// web_add_cookie("wordpress_613541581fd3dd54ee5153849996d0f6=admin|1304215578|616ad0d48cfd28158b012254e00fe732; DOMAIN=demo.opensourcecms.com");
//
web_url("wp-login.php",
"URL=http://demo.opensourcecms.com/wordpress/wp-login.php",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"URL=wp-admin/images/button-grad.png", ENDITEM,
"URL=wp-admin/images/white-grad.png", ENDITEM,
"URL=wp-admin/images/logo-login.gif", ENDITEM,
LAST);
lr_start_transaction("Login_WordPress");
// 注意,该函数应该插入到提交时会出现该字段的地方之前。
//web_reg_find("Text=Dashboard",
// "Search=Body",
// LAST);
web_submit_form("wp-login.php_2",
"Snapshot=t3.inf",
ITEMDATA,
"Name=log", "Value={UserName}", ENDITEM,
"Name=pwd", "Value={Password}", ENDITEM,
"Name=rememberme", "Value=<OFF>", ENDITEM,
"Name=wp-submit", "Value=Log In", ENDITEM,
EXTRARES,
"URL=wp-admin/images/wp-logo.png?ver=20100531", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/fav-arrow.gif?ver=20100531", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/menu.png?ver=20100531", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/menu-bits.gif?ver=20100610", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/menu-dark.gif", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/menu-arrows.gif", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/screen-options-toggle.gif?ver=20100531", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/icons32.png?ver=20100531", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/gray-grad.png", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-includes/js/thickbox/loadingAnimation.gif", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
"URL=wp-admin/images/fade-butt.png", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", ENDITEM,
LAST);
lr_end_transaction("Login_WordPress", LR_AUTO);
web_url("index-extra.php",
"URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_incoming_links",
"Resource=0",
"RecContentType=text/html",
"Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",
"Snapshot=t4.inf",
"Mode=HTML",
LAST);
web_url("index-extra.php_2",
"URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_primary",
"Resource=0",
"RecContentType=text/html",
"Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
web_url("index-extra.php_3",
"URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_secondary",
"Resource=0",
"RecContentType=text/html",
"Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);
web_url("index-extra.php_4",
"URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_plugins",
"Resource=0",
"RecContentType=text/html",
"Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
web_url("index-extra.php_5",
"URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_quick_press",
"Resource=0",
"RecContentType=text/html",
"Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",
"Snapshot=t8.inf",
"Mode=HTML",
LAST);
if(status == LR_FAIL) {
lr_error_message("Log on failed");
return -1;
}
else{
lr_output_message("Log on successfully");
return 0;
}
}