如何用好LoadRunner中的檢查點(2)

發表于:2012-01-20來源:未知作者:xql00163com點擊數: 標簽:
ITEMDATA, Name=username, Value=jojo, ENDITEM, Name=password, Value=bean, ENDITEM, Name=login.x, Value=35, ENDITEM, Name=login.y, Value=14, ENDITEM, LAST); // Check result if (atoi(lr_eval_string({Welc

  ITEMDATA,

  "Name=username", "Value=jojo", ENDITEM,

  Name=password", "Value=bean", ENDITEM,

  "Name=login.x", "Value=35", ENDITEM,

  "Name=login.y", "Value=14", ENDITEM,

  LAST);

  // Check result

  if (atoi(lr_eval_string("{Welcome_Count}")) > 0){ //判斷如果Welcome字符串出現次數大于0

  lr_output_message("Log on successful."); }//在日志中輸出Log on successful

  else{ //如果出現次數小于等于

  lr_error_message("Log on failed"); //在日志中輸出Log on failed

  return(0); }

  我覺得這個方法非常有用,我們可以舉一反三,應用到我們實際的項目

  注:在錄制過程中添加的檢查點,用到的函數是web_reg_find(),且參數只有“Text=”

  3、web_image_check()函數參數說明:

  web_image_check("web_image_check","Alt=","Src=",LAST);

  參數解釋:“Alt”和“Src”的值直接取該圖片在網頁源代碼中相應參數的值;

  注意事項:使用該函數時,要在Vuser->Run-Tme Settings中勾選Enable Image and text check,具體操作請看web_find()中的注意事項。

  經過測試,該函數用到查找內容前面或后面,都不影響查找結果。

  舉例說明(腳本)

  該腳本記錄的是登陸系統后退出的操作,在腳本中用到atoi()函數和lr_eval_string(”{SaveCount定義的變量}”)兩個函數結合使用,判斷查找內容出現的次數是否大于0,若大于0,則輸入登錄成功的信息。

  vuser_init()

  {

  web_url("xjcost",

  "URL=http://gczj-server8:9205/xjcost/",

  "Resource=0",

  "RecContentType=text/html",

  "Referer=",

  "Snapshot=t1.inf",

  "Mode=HTML",

  EXTRARES,

  "Url=jsp/images/index/index.swf", ENDITEM,

  "Url=jsp/images/index/xxfb2.gif", ENDITEM,

  "Url=jsp/images/index/ywpt2.gif", ENDITEM,

  LAST);

  web_url("userAction.struts",

  "URL=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",

  "Resource=0",

  "RecContentType=text/html",

  "Referer=",

  "Snapshot=t2.inf",

  "Mode=HTML",

  LAST);

  return 0;

  }

  Action()

  {

  lr_start_transaction("Log_on");

  lr_rendezvous("Log_on");

  web_add_cookie("userAccount=admin; DOMAIN=gczj-server8");

  web_reg_find("Text=歡迎您",

  "SaveCount=歡迎您_Count",

  LAST);

  web_image_check("web_image_check",

  "Src=/xjcost/jsp/images/index1/edit_01.gif",

  LAST);

  web_submit_data("userLogin.struts",

  "Action=http://gczj-server8:9205/xjcost/userLogin.struts?actionType=userLogin",

  "Method=POST",

  "RecContentType=text/html",

  "Referer=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",

  "Snapshot=t3.inf",

  "Mode=HTML",

  ITEMDATA,

  "Name=userAccount", "Value=admin", ENDITEM,

  "Name=pwd", "Value=1111", ENDITEM,

  EXTRARES,

  "Url=jsp/images/index1/edit_01a.gif", "Referer=http://gczj-server8:9205/xjcost/userLogin.struts?actionType=userLogin", ENDITEM,

  LAST);

  web_find("web_find",

  "What=歡迎您",

  LAST);

  lr_end_transaction("Log_on",LR_AUTO);

  //檢查是否登錄成功

  //如果“歡迎您”這個字符出現次數大于0,輸出“Log on successfully!”

  if(atoi(lr_eval_string("{歡迎您_Count}"))>0)

  lr_output_message("Log on successfully!");

  else

  lr_error_message("Log on failed!");

  return 0;

  return 0;

  }

  //atoi()函數的作用是將一個ASCII字符串轉換為整型

  //lr_eval_string()函數作用是取得參數值,將字符串變量中的參數值替換為當前的參數值并將這個字符串返回

  vuser_end()

  {

  lr_think_time(4);

  web_url("userAction.struts_2",

  "URL=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",

  "Resource=0",

  "RecContentType=text/html",

  "Referer=",

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97