当前位置:网站首页>接口测试进阶接口脚本使用—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);
}
}边栏推荐
- 某马旅游网站开发(对servlet的优化)
- 备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- If an exception is thrown in the constructor, the best way is to prevent memory leakage?
- 攻防世界Web进阶区unserialize3题解
- 什么是负载均衡?DNS如何实现负载均衡?
- How can CSDN indent the first line of a paragraph by 2 characters?
- 35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
- Jouer sonar
- Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
猜你喜欢

How to learn a new technology (programming language)

Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现

Using Google test in QT

2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:

华为交换机S5735S-L24T4S-QA2无法telnet远程访问

CoinDesk评波场去中心化进程:让人们看到互联网的未来

redis你到底懂不懂之list

每日刷题记录 (十六)

【史上最详细】信贷中逾期天数统计说明

第一讲:链表中环的入口结点
随机推荐
Operating system principle --- summary of interview knowledge points
How to add automatic sorting titles in typora software?
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
5G NR 系统消息
华为交换机S5735S-L24T4S-QA2无法telnet远程访问
3年经验,面试测试岗20K都拿不到了吗?这么坑?
华泰证券官方网站开户安全吗?
When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
22年秋招心得
The result of innovation in professional courses such as robotics (Automation)
快速上手使用本地测试工具postman
“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
Relevant methods of sorting arrays in JS (if you want to understand arrays, it's enough to read this article)
Open display PDF file in web page
面试题详解:用Redis实现分布式锁的血泪史
【编程题】【Scratch二级】2019.12 飞翔的小鸟
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
How to measure whether the product is "just needed, high frequency, pain points"