当前位置:网站首页>接口测试进阶接口脚本使用—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);
}
}边栏推荐
- Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better
- Tools for debugging makefiles - tool for debugging makefiles
- 5G NR 系统消息
- Using Google test in QT
- Qt不同类之间建立信号槽,并传递参数
- Reading notes 004: Wang Yangming's quotations
- 爬虫实战(八):爬表情包
- Fully automated processing of monthly card shortage data and output of card shortage personnel information
- 3 years of experience, can't you get 20K for the interview and test post? Such a hole?
- [programming problem] [scratch Level 2] March 2019 draw a square spiral
猜你喜欢

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

How to measure whether the product is "just needed, high frequency, pain points"

SQL knowledge summary 004: Postgres terminal command summary
![[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

玩轉Sonar

80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?

去了字节跳动,才知道年薪 40w 的测试工程师有这么多?

5G NR 系统消息
![[programming problem] [scratch Level 2] draw ten squares in December 2019](/img/4f/14ea8e786b7f8b0a263aa5c55abf15.png)
[programming problem] [scratch Level 2] draw ten squares in December 2019
![[programming problem] [scratch Level 2] December 2019 flying birds](/img/5e/a105f8615f3991635c9ffd3a8e5836.png)
[programming problem] [scratch Level 2] December 2019 flying birds
随机推荐
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
51与蓝牙模块通讯,51驱动蓝牙APP点灯
How to insert highlighted code blocks in WPS and word
DNS 系列(一):为什么更新了 DNS 记录不生效?
Go learning notes (1) environment installation and hello world
[programming problem] [scratch Level 2] draw ten squares in December 2019
华泰证券官方网站开户安全吗?
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
玩轉Sonar
去了字节跳动,才知道年薪 40w 的测试工程师有这么多?
Tools for debugging makefiles - tool for debugging makefiles
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
如果在构造函数中抛出异常,最好的做法是防止内存泄漏?
在网页中打开展示pdf文件
Go learning notes (2) basic types and statements (1)
智慧监管入场,美团等互联网服务平台何去何从
ABAP ALV LVC模板
Development of a horse tourism website (optimization of servlet)
80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?