当前位置:网站首页>接口测试进阶接口脚本使用—apipost(预/后执行脚本)
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
2022-07-07 22:29:00 【InfoQ】

- 编写JS函数等实现复杂计算;
- 变量的打印
- 定义、获取、删除、清空环境变量
- 定义、获取、删除、清空全局变量
- 获取请求参数
- 动态添加、删除一个header请求参数
- 动态添加、删除一个query请求参数
- 动态添加、删除一个body请求参数
- 发送HTTP请求

function _random(){
return '你好,中国' + Math.random();
}apt.globals.set("random_var", _random());
apt.variables.set("key", "value"); // 设置一个值为value的环境变量key
apt.variables.get("key"); // 获取环境变量key的值
apt.variables.delete("key"); // 删除环境变量key
apt.variables.clear(); // 清空定义的全部环境变量apt.globals.set("key", "value"); // 设置一个值为value的全局变量key
apt.globals.get("key"); // 设置一个值为value的全局变量key
apt.globals.delete("key"); // 设置一个值为value的全局变量key
apt.globals.clear(); // 清空定义的全部全局变量apt.setRequestHeader("key", "value"); // 动态添加一个键为key值为value的header参数
apt.removeRequestHeader("key"); // 删除header参数中键为key的参数apt.setRequestQuery("key", "value"); // 动态添加一个键为key值为value的query参数
apt.removeRequestQuery("key"); // 删除query参数中键为key的参数apt.setRequestBody("key", "value");// 动态添加一个键为key值为value的body参数 只针对 form-data、urlencode有效
apt.removeRequestBody("key");//删除body中键为key的参数 只针对 form-data、urlencode有效$.ajax({
url:"https://echo.apipost.cn/get.php",
method:"POST",
headers:{
"content-type":"application/json"
},
timeout:"10000",
async:false, // 记住此项设置为 false,必须同步请求
data:JSON.stringify({"email":"[email protected]","password":"123456"}),
success:function (response) {
apt.globals.set("bigint",response.bigint);
}
}边栏推荐
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
- 爬虫实战(八):爬表情包
- Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better
- Go learning notes (1) environment installation and hello world
- 韦东山第二期课程内容概要
- ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
- Set up personal network disk with nextcloud
- Seven years' experience of a test engineer -- to you who walk alone all the way (don't give up)
- Usage of limit and offset (Reprint)
- 从服务器到云托管,到底经历了什么?
猜你喜欢

某马旅游网站开发(登录注册退出功能的实现)

52岁的周鸿祎,还年轻吗?

80%的人答错,苹果logo上的叶子到底朝左还是朝右?

Is Zhou Hongyi, 52, still young?

Preliminary test of optical flow sensor: gl9306

The result of innovation in professional courses such as robotics (Automation)

快速上手使用本地测试工具postman

关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知

Zhou Hongqi, 52 ans, est - il encore jeune?

The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
随机推荐
The underlying principles and templates of new and delete
52岁的周鸿祎,还年轻吗?
How to measure whether the product is "just needed, high frequency, pain points"
【编程题】【Scratch二级】2019.12 绘制十个正方形
Reptile practice (VIII): reptile expression pack
玩轉Sonar
Daily question brushing record (16)
Binder核心API
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
How to insert highlighted code blocks in WPS and word
第一讲:链表中环的入口结点
Les mots ont été écrits, la fonction est vraiment puissante!
Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis
How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
数据库查询——第几高的数据?
Flask learning record 000: error summary
How to learn a new technology (programming language)
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
Smart regulation enters the market, where will meituan and other Internet service platforms go