当前位置:网站首页>接口测试进阶接口脚本使用—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);
}
}边栏推荐
- Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
- 52岁的周鸿祎,还年轻吗?
- 搭建ADG过程中复制报错 RMAN-03009 ORA-03113
- STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
- 数据库查询——第几高的数据?
- Scrapy framework
- C# 泛型及性能比较
- Set up personal network disk with nextcloud
- QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2
- 赞!idea 如何单窗口打开多个项目?
猜你喜欢
![[basis of recommendation system] sampling and construction of positive and negative samples](/img/4b/753a61b583cf38826b597fd31e5d20.png)
[basis of recommendation system] sampling and construction of positive and negative samples

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

After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?

“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点

Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet

单机高并发模型设计

DNS 系列(一):为什么更新了 DNS 记录不生效?

What if the testing process is not perfect and the development is not active?

【编程题】【Scratch二级】2019.12 绘制十个正方形

赞!idea 如何单窗口打开多个项目?
随机推荐
某马旅游网站开发(登录注册退出功能的实现)
玩轉Sonar
关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
【编程题】【Scratch二级】2019.03 垃圾分类
韦东山第二期课程内容概要
如果在构造函数中抛出异常,最好的做法是防止内存泄漏?
The difference between -s and -d when downloading packages using NPM
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
How to add automatic sorting titles in typora software?
[programming questions] [scratch Level 2] March 2019 garbage classification
Automated testing: robot framework is a practical skill that 90% of people want to know
52歲的周鴻禕,還年輕嗎?
5G NR 系统消息
ReentrantLock 公平锁源码 第0篇
51与蓝牙模块通讯,51驱动蓝牙APP点灯
Relevant methods of sorting arrays in JS (if you want to understand arrays, it's enough to read this article)
【测试面试题】页面很卡的原因分析及解决方案
单机高并发模型设计
80%的人答错,苹果logo上的叶子到底朝左还是朝右?
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道