LR常用函数以及调用自定义函数
2.LR常用函数以及调用自定义函数
2.1.LR常用函数以及对信息的判断
2.1.1. LR内部自定义函数
在LR脚本中定义变量和编写自定义函数,需将变量的声明放在脚本其他内容的上方,否则会提示【illegal statement termination】
1.编写简单函数
int sum(int a,int b)//简单的求和函数
{
return a+b;
}
AdvSearch()
{
lr_message("sum = 10+2=%d",sum(9,2));
return 0;
}
变量的声明要写在Action的前面,否则会提示【illegal statement termination】
图表12

解决方法:将int x,int ret的声明,紧跟char*showString之后。
2.随机字母串
int itera_num,rand_num,rand_num1,rand_case,i;
char StrTable[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%&*()_+|}{:><,./;[]=-"; //大小写字母52个+数字10个+特殊字符26个=88个;~!@#$%&*()_+|}{:><,./;[]=-
char i_Alpa[36]="";
web_set_max_html_param_len("12400");
itera_num=rand()%36;
for (i=0;i<=itera_num;i++){
rand_num=rand()%88;
strncat(i_Alpa,StrTable+rand_num,1);
}
lr_save_string(i_Alpa,"autoAlpaValue");
2.1.2.常用LR请求函数
使用快捷键Alt+Insert调出函数参数快捷编辑工具,如图:
图表13

- 请求URL中传参
web_url("Login",
"URL=https://secure.computing.com/scripts/login.asp?user=(username)&session={ssid}", "RecContentType=text/html", //Expected content–type LAST );
- 键值对传参
web_submit_data("default.aspx",
"Action=http://lazarus/flightnet/default.aspx", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://lazarus/flightnet/", "Snapshot=t7.inf", "Mode=HTML", //提交数据表单,键值对。 ITEMDATA, "Name=grpType", "Value=radRoundtrip", ENDITEM, "Name=lstDepartingCity", "Value=DEN", ENDITEM, //或者提交文件 ITEMDATA, "Name=userFile0", "Value=E:\\sense_sensibility\\Elinor.htm", "File=yes", "ContentType=text/html", // .txt :"text/plain" FilePath=Elinor.txt", "ContentTransferEncoding=html/text", ENDITEM, LAST );
- body体传参
web_custom_request("post_query.exe", "Method=POST",
"URL=http://lazarus/cgi–bin/post_query.exe", "Body={\"action\":\"{actionName}\",\"name\":\"{userName}\",\"secret\":\"{password}\"}", "TargetFrame=", LAST );
以上方式是传递的信息请求体中,若存在信息需要在请求头Header中传递的,需要在请求前添加web_add_header,比如E:\项目资料\工作总结\接口测试\33.OKMS日志服务接口测试、Knowlege Management System 接口测试脚本中。
- web_add_heade传参
/*
*用户名密码方式登陆
* */
web_add_header("action","name_pass_login");
web_add_header("name","{userName}");
web_add_header("secret","{secretValue}");
web_add_header("sid","");
web_add_header("uid","");
web_add_header("app_id","odata_us3");
web_add_header("timestamp","{tStamp}");
web_add_header("sign","{signValue}");
web_add_header("ip","");
web_add_header("did","\{123456\}");
web_add_header("mobile","");
web_add_header("location","");
lr_start_transaction("name_pass_Login");
web_reg_save_param("json","LB=\r\n{", "RB=", LAST);
web_custom_request("login",
"URL=http://192.168.100.198:8010/api/login",
"Method=GET",
"TargetFrame=",
"RecContentType=text/json",
"Referer=",
"Mode=HTML",
"EncType=text/json", //"Body={\"action\":\"{actionName}\",\"name\":\"{userName}\",\"secret\":\"{secretValue}\"}",
LAST );
2.1.3.常用函数
- //设置保存参数最大长度;
web_set_max_html_param_len("10240");
- //保存系统当前时间距离1970年的秒数
web_save_timestamp_param("tStamp",LAST);
输出:Notify: Saving Parameter "tStamp = 1470030946475".//取第0-10位保存;
- //取第0-10位保存
lr_save_var(lr_eval_string("{tStamp}"),10,0,"tStamp");
输出:Notify: Saving Parameter "tStamp = 1470030946".
- //将参数subStamp的值复制给变量pre中。
strcpy(pre,lr_eval_string("{subStamp}"));
- //A+B的
strcat(A, B);
- // A+(B的前n位);
strncat(A,B,n);
- //比较A=B返回 =0,A>B返回 >0;
strcmp(A,B) == 0
// char * string = "His Excellency the Duke of Exeter"; char * first_x, * last_x;
- //查找在字符串中第一次出现x的位置;
first_x = (char *)strchr(string, 'x');
- //查找在字符串中最后一次出现x的位置;
last_x = (char *)strrchr(string, 'x');
备注:Returns a pointer to the first occurrence of string2 in string1. If string2 is not found in string1 the function returns NULL.
- //atoi将字符串型变为整型;passKey="123456", pre="147003"
iKey = atoi(passKey)+atoi(pre);
输出:Notify: Saving Parameter "KeyValue = 270459".
- //将整数转化为字符串,10表示按照十进制int itoa( int value, char *str, int radix);
itoa(id,strid,10); //int id = 56;
输出:strid = 56;若将10修改为2,二进制输出strid=111000;
- //将整型做为字符串保存到参数中。
lr_save_int(iKey,"KeyValue");
- //被检索字符串,被检索字符串长度,取检索到的第几次的值,检索词,从检索词后偏移几位开始,截取长度,保存参数名。
lr_save_searched_string(lr_eval_string("{json}"),strlen(lr_eval_string("{json}")), 0,"\"SID\":\"",0,32,"SIDValue");
- //保存返回值;
web_reg_save_param("p", "LB/BIN=\\x3F\\xDD", "RB/BIN=\\xCCb", LAST ); //二进制
- //将值写入参数filename中,int index = 56; char filename[64], * suffix = "txt";
sprintf(filename, "log_%d.%s", index, suffix);
输出:Notify: Saving Parameter " filename = log_56.txt".
2.1.4.信息判断
web_reg_save_param("json ", "LB =< ", "RB = >", LAST );
…………
//获取返回信息
lr_save_var(lr_eval_string("{json}"),5,0,"StartWith");
//判断返回信息与预期值
if(strcmp(lr_eval_string("{StartWith}"),"\"SID\"") == 0)
{
// lr_message("The SIDValue : %s",lr_eval_string("{SIDValue}"));
lr_end_transaction("name_pass_Login", LR_PASS);
}else (strcmp(lr_eval_string("{StartWith}")," \"err") == 0){
lr_save_var(lr_eval_string("{json}"),13,0,"StartStr");
if(strcmp(lr_eval_string("{StartStr}")," \"error\": \"-1") == 0)
{
lr_message("The json : %s",lr_eval_string("{json}"));
lr_end_transaction("name_pass_Login", LR_FAIL);
}else{
lr_end_transaction("name_pass_Login", LR_PASS);
}
}
LR常用函数以及调用自定义函数的更多相关文章
- 如何在sqlite3连接中创建并调用自定义函数
#!/user/bin/env python # @Time :2018/6/8 14:44 # @Author :PGIDYSQ #@File :CreateFunTest.py '''如何在sql ...
- PHP中call user func()和call_user_func_array()调用自定义函数小结
call_user_func() 和 call_user_func_array(),通过传入字符串函数,可以调用自定义函数,并且支持引用,都允许用户调用自定义函数并传入一定的参数: 1.mixed c ...
- Python第七天 函数 函数参数 函数里的变量 函数返回值 多类型传值 函数递归调用 匿名函数 内置函数
Python第七天 函数 函数参数 函数里的变量 函数返回值 多类型传值 函数递归调用 匿名函数 内置函数 目录 Pycharm使用技巧(转载) Python第一天 ...
- python27期day09:函数的初始、函数的定义、函数的调用、函数的返回值、函数的参数、作业题。
1.函数的作用:封装代码.大量的减少了重复的代码. 2.全局空间:顶行写的就是全局空间. 图解 : 3.函数的定义: def 是一个关键字.申明要定义一个函数 my_len 函数的名字.遵循变量命名的 ...
- 使用 {$INCLUDE} 或 {$I} 指令管理和调用自定义函数
这是一个简单.方便而又实用的小技巧. 譬如这段代码中有四个定义函数: MyAdd.MyDec.MyMul.MyDiv unit Unit1; interface uses Windows, Mes ...
- 微信小程序wxml文件中调用自定义函数
想在微信小程序的wxml文件里自如的像vue那样调用自定义的方法,发现并不成功,得利用WXS脚本语言. WXS脚本语言是 WeiXin Script 脚本语言的简称,是JavaScript.JSON. ...
- ThinkPHP 3.2 调用自定义函数库
ThinkPHP3.2 和3.1 区别还是有点大的 引入了命名空间,强化了驱动化和行为,增强了模块化的概念和对云平台的支持,并改进了诸多的细节.主要改进包括:模块化架构的全新设计全新命名空间和自动导入 ...
- Mysql5.7创建存储过程中调用自定义函数报错Not allowed to return a result set from a function
因为很多存储过程都会共用一段sql语句,所以我把共用的sql封装成一个自定义函数 AddCapital(); 然后通过存储过程调用,创建存储过程会报错1415,Not allowed to retur ...
- Python基础(函数,函数的定义,函数的调用,函数的参数,递归函数)
1.函数 我们知道圆的面积计算公式为: S = πr2 当我们知道半径r的值时,就可以根据公式计算出面积.假设我们需要计算3个不同大小的圆的面积: r1 = 12.34 r2 = 9.08 r3 = ...
随机推荐
- 【python】获取指定网页上的所有超级链接
# -*- coding: utf-8 -*- import urllib2 import re #connect to a URL website = urllib2.urlopen("h ...
- jquery 通知页面变化
var PageTitleNotification = { Vars: { OriginalTitle: document.title, Interval: null, IsNotificationE ...
- Mybatis与Hibernate的区别
首先简单介绍下两者的概念: Hibernate :Hibernate 是当前最流行的ORM框架,对数据库结构提供了较为完整的封装. Mybatis:Mybatis同样也是非常流行的ORM框架,主要着力 ...
- Java BigDecimal和double
BigDecimal类 对于不需要任何准确计算精度的数字可以直接使用float或double,但是如果需要精确计算的结果,则必须使用BigDecimal类,而且使用BigDecimal类也可以进行大数 ...
- IIS 7.0 部署MVC
开发的MVC 3.0 项目,在部署服务上还是与需要花一点功夫,这里把遇到的问题罗列出来. 本文主要介绍IIS 7.5中安装配置MVC 3.0的具体办法! 部署必备: Microsoft .net Fr ...
- 黄聪:日租VPS中FileZilla_Server配置方法
1.关闭VPS中IIS的FTP服务 2.FileZilla_Server 监听端口 21 3.FTP客户端端口为11311(看服务商给出的)
- Python的第三天
一.字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: ...
- AIX上增加逻辑卷时报错误0516-787 extendlv: Maximum allocation for logical volume
AIX上增加逻辑卷时报错误0516-787 extendlv: Maximum allocation for logical volume jdelv02 is 512. 在往aix使用chfs -a ...
- 整整十年 - Agent Framework for TypeScript 2.0
十年前,我发布了 Agent Framework for .NET 2.0 今天,Agent 又开始了新的旅程, 这次支持的语言是 TypeScript 2.0 上需求:init函数只能被调用一次 废 ...
- hmtl弹出框样式
@model Web.Manager.Models.SendMessage @{ ViewBag.Title = "消息发布"; Layout = null;} <link ...