LoadRunner例子:检查点为参数的一个例子

LoadRunner例子:检查点为参数的一个例子

 

     检查点是LoadRunner的一个功能,用来验证业务功能的正确性。如果检查的内容是变化的,脚本该如何写呢?

     问题提出:LoadRunner订票网站例子中,创建一个虚拟用户脚本,在登陆完成之后,设立一个检查点,来检查“welcome, xxx”。其中xxx为登陆的用户名称。

      解决方法:

     1)使用web_find() 做检查点

     Action()
{

//连接字符串,把welcome和用户名组合成一个字符串

 char teststring[1024]="Welcome, ";
 strcat( teststring,lr_eval_string("{username}") );
 lr_output_message("%s", teststring);
 lr_save_string( teststring,"findtext" );

 // [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf]

//Parameter {WCSParam_Diff1} created by Correlation Studio

//关联操作
 web_reg_save_param("WCSParam_Diff1",
  "LB=userSession value=",
  "RB=>",
  "Ord=1",
  "RelFrameId=1.2.1",
  "Search=Body",
  "IgnoreRedirections=Yes",
  LAST);


 web_url("WebTours",
  "URL=http://127.0.0.1:1080/WebTours/",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTML",
  LAST);
 lr_think_time(11);
   

 lr_start_transaction("test");


 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=t2.inf",
  "Mode=HTML",
  ITEMDATA,
  "Name=userSession", "Value={WCSParam_Diff1}", ENDITEM,
  "Name=username", "Value={username}", ENDITEM,     //参数化用户名
  "Name=password", "Value=bean", ENDITEM,
  "Name=JSFormSubmit", "Value=off", ENDITEM,
  "Name=login.x", "Value=42", ENDITEM,
  "Name=login.y", "Value=13", ENDITEM,
  LAST);

//检查点

 web_find("web_find",
  "What={findtext}",
  LAST);
   

 lr_end_transaction("test", LR_AUTO);


 return 0;
}

     2)使用web_reg_find()做检查点

Action()
{

//字符串操作,生成要检查的字符串变量

char teststring[1024]="Welcome, <b>";
 strcat( teststring,
  lr_eval_string("{username}") );
 lr_output_message("%s", teststring);
 lr_save_string( teststring,"findtext" );

 //关联

// [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf]   Parameter {WCSParam_Diff1} created by Correlation Studio
 web_reg_save_param("WCSParam_Diff1",
  "LB=userSession value=",
  "RB=>",
  "Ord=1",
  "RelFrameId=1.2.1",
  "Search=Body",
  "IgnoreRedirections=Yes",
  LAST);
 web_url("WebTours",
  "URL=http://127.0.0.1:1080/WebTours/",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTML",
  LAST);
 lr_think_time(11);
   

 lr_start_transaction("test");

 //检查点
 web_reg_find("Text={findtext}",
  "Search=Body",
  LAST);

 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=t2.inf",
  "Mode=HTML",
  ITEMDATA,
  "Name=userSession", "Value={WCSParam_Diff1}", ENDITEM,
  "Name=username", "Value={username}", ENDITEM,  //参数化登陆名称
  "Name=password", "Value=bean", ENDITEM,
  "Name=JSFormSubmit", "Value=off", ENDITEM,
  "Name=login.x", "Value=42", ENDITEM,
  "Name=login.y", "Value=13", ENDITEM,
  LAST);
   

 lr_end_transaction("test", LR_AUTO);


 return 0;
}

 
转自:http://www.51testing.com/html/66/34866-73250.html
原文地址:https://www.cnblogs.com/abcd19880817/p/7201511.html