常用函数总结
  1. web_url
该函数用于Web-HTTP/HTML协议中处理get处理,具体参数如下: web_url( "web_url",   //步骤名称,随便取    "URL= http://www.youdao.com", //URL地址    "TargetFrame=",   //是否在新窗口打开,不用设置    "Resource=1",//一个指示url是否一个资源的值,。两种情况,0标识url不是一个资源,1是一个资源    "Referer=",     //原链接,从哪一个链接跳转过来的    "Mode=HTML",    //录制模式与级别 HTML或者HTTP    LAST);
  1. web_submit_data
该函数用于Web-HTTP/HTML协议中处理post和get处理,post用的比较多,处理无状态或者上下文无关的表单提交,具体参数如下:(参数意义同上的就不做解释了) web_submit_data("login", //步骤名称,随便取   "Action= http://120.78.128.25:8765/Frontend/Index/login", //URL地址   "Method=POST",       //post请求   "EncType=application/x-www-form-urlencoded;charset=UTF-8",   "TargetFrame=",   "Referer= http://120.78.128.25:8765/Index/login.html",   "Mode=HTML",   ITEMDATA,     //分隔符号,表明属性与数据域的分隔   "Name=phone", "Value=13825161923", ENDITEM,   "Name=password", "Value=lemon123", ENDITEM,   "Name=vcode", "Value=", ENDITEM,   "Name=remember_me", "Value=1", ENDITEM,   "Name=notify_url", "Value=", ENDITEM,   LAST);
  1. web_custom_request
该函数模拟HTTP请求,可以用于Web-HTTP/HTML和Web Services协议中,处理post和get处理,具体参数如下(数据来源接口文档,或者知道接口url使用soap工具获得): web_custom_request("注册",     "URL= http://192.168.204.133:8080/mobile/api/user/register/",   "Method=POST",   "TargetFrame=",   "Resource=1",   "Referer=",   "Mode=HTTP",   "EncType=application/json",//以json的方式提交数据   "Body={\"mobile\":\"{mobile}\",\"password\":\"{password}\",\"platform\":\"windows\",\"username\":\"{username}\",\"sex\":1,\"age\":2,\"email\":\"{email}\",\"code\":\"3367\"}", //输入的请求信息体   LAST); 该函数也可做web service协议  web_custom_request("web_custom_request",  "URL= http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",  "Method=POST",  "Resource=0",  "Referer=",  "Mode=HTTP",  "EncType=text/xml; charset=utf-8", //这是输入请求体  "Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"  "<soap12:Envelope xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\" http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\" http://www.w3.org/2003/05/soap-envelope\">"  " <soap12:Body>"  "<getWeatherbyCityName xmlns=\" http://WebXml.com.cn/\">"  "<theCityName>string</theCityName>"  "</getWeatherbyCityName>"  "</soap12:Body>"  "</soap12:Envelope>",    LAST);
  1. Web_service_call
当从开发那边知道wdsl信息,接口都是SOAP的形式传输xml信息,使用web service协议做脚本,可使用web_service_call函数,具体参数如下: web_service_call(        "StepName=getWeatherbyCityName_101", //步骤名称       "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",//服务名称,soap,获取的接口       "ResponseParam=response",//返回参数信息       "Service=WeatherWebService", //webservice的服务       "ExpectedResponse=SoapResult", //请求的返回       "Snapshot=t1555551364.inf", //快照       BEGIN_ARGUMENTS,  //开始输入       "theCityName=南京",  //输入的参数值       END_ARGUMENTS,    //结束输入       BEGIN_RESULT,   //开始输出       "getWeatherbyCityNameResult=Param_getWeatherbyCityNameResult",       "getWeatherbyCityNameResult/*[2]=Param_cityname",//返回的城市       END_RESULT,//结束输出             LAST);
  1. Web_service_call
当知道接口报文信息且以SOAP 1.2 请求和响应示例可以使用soap_request()函数 ,具体参数如下: soap_request( "StepName=SOAP Request", //步骤  "URL= http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",         "SOAPEnvelope=" //发送到服务器的XML   "<soap:Envelope xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\" http://www.w3.org/2001/XMLSchema\" xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\">"   "<soap:Body>"   "<getWeatherbyCityName xmlns=\" http://WebXml.com.cn/\">"   "<theCityName>南京</theCityName>"    "</getWeatherbyCityName>"    "</soap:Body>"    "</soap:Envelope>",                            "SOAPAction= http://WebXml.com.cn/getWeatherbyCityName",          "ResponseParam=response",  //存储服务器响应返回参数 "Snapshot=t1555556002.inf",                         LAST);
  1. Web_reg_save_param
关联函数,需要放在请求之前,可用于token,session等一些动态值的关联,也可以用该方????????????????????????????  web_reg_save_param(    "res_3",  ///将得到的数据存放到res_3中去    "LB=",        //左边界    "RB=",        //右边界    LAST);
  1. Web_reg_save_param_ex
关联函数,需要放在请求之前,可用于token,session等一些动态值的关联,也可以用该方????????????????????????????  web_reg_save_param_ex(   "ParamName=login_Tommy",//关联到的值放在login_Tommy中   "LB=class=\"success\">",//左边界   "RB=</p>", //右边界   "Ordinal=1",//取第一个值,如果是All的话,取所有的值   SEARCH_FILTERS,   LAST);
  1. Web_reg_find
查找检查点,判断事务是否正确,返回的是int型 web_reg_find( "Search=All", //查看范围   "Text=xiaozhang",//查找内容   LAST);
  1. lr_eval_string
LR中不能直接显示自定义的字符串,需要用这个函数编译一下 lr_eval_string("{username}");
  1. lr_output_message
打印字符串 lr_output_message(lr_eval_string("{username}"));
  1. lr_error_message
高亮打印字符串 lr_error_message(lr_eval_string("{username}"));
  1. lr_save_string
把lr自定义的参数转化为LR的参数,即将string1赋值给string2 lr_save_string("string1","string2");
  1. lr_convert_string_encoding
编码格式转换,改变字符串的编码格式,共有四个参数,第一个参数为原字符串,第二个为原编码格式,第三个为新的编码格式,第四个参数为编译之后放置的地方编码格式有三种第一:LR_ENC_UTF8对应uft-8,第二:LR_ENC_SYSTEM_LOCALE对应无编码,第三:LR_ENC_UNICODE 对应"ucs-2" lr_convert_string_encoding(lr_eval_string("{res_1}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"rusurl_1");
  1. strcmp
把比较两个字符串 if(strcmp(lr_eval_string("{sting1}"),"string2")==0);
  1. atoi
比较两个int类型 if(atoi(lr_eval_string("{int}"),2)==0);
  1. web_convert_param
将字符串与URL之间进行转换,比如token值在url中 web_convert_param( "tokenURL",//参数的名称,转换后的字符串被保存在该参数中 "SourceEncoding=PLAIN",//编码的数据类型HTML,URL,Plain "TargetEncoding=URL",//目标数据的编码类型  LAST);   17. lr_paramarr_random,lr_paramarr_idx 第一个函数是随机取数组中的值,第二个函数是根据下标去数组中的值 //数组----[1,2,3,4]   数组内的数据形式必须一致      lr_save_string(" www.baidu.com","website_1");      lr_save_string(" www.taobao.com","website_2");      lr_save_string(" www.google.com","website_3");      lr_save_string(" www.youdao.com","website_4");      lr_save_string("4","website_count");     //1)获取数组里面的值,随机获取值      lr_save_string(lr_paramarr_random("website"),"website_test");      lr_error_message("得到的随机网址为:%s",lr_eval_string("{website_test}"));       // 2)获取数组里面的值,根据指标获取  从0开始的      lr_save_string(lr_paramarr_idx("website",1),"website_test1");      lr_error_message("根据下标得到的网址为:%s",lr_eval_string("{website_test1}"));
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄