当前位置:网站首页>接口测试进阶接口脚本使用—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);
}
}边栏推荐
- [the most detailed in history] statistical description of overdue days in credit
- The underlying principles and templates of new and delete
- Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
- How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
- RPA云电脑,让RPA开箱即用算力无限?
- If an exception is thrown in the constructor, the best way is to prevent memory leakage?
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
- 他们齐聚 2022 ECUG Con,只为「中国技术力量」
- Seven years' experience of a test engineer -- to you who walk alone all the way (don't give up)
- 52岁的周鸿祎,还年轻吗?
猜你喜欢

【测试面试题】页面很卡的原因分析及解决方案

C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks

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

QT and OpenGL: load 3D models using the open asset import library (assimp)
![[the most detailed in history] statistical description of overdue days in credit](/img/f7/5c3cbfec5b010171376ac122c704b2.png)
[the most detailed in history] statistical description of overdue days in credit

Development of a horse tourism website (optimization of servlet)

52歲的周鴻禕,還年輕嗎?

ReentrantLock 公平锁源码 第0篇

Les mots ont été écrits, la fonction est vraiment puissante!

After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
随机推荐
When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
80%的人答错,苹果logo上的叶子到底朝左还是朝右?
22年秋招心得
[C language] objective questions - knowledge points
Zhou Hongqi, 52 ans, est - il encore jeune?
【编程题】【Scratch二级】2019.09 制作蝙蝠冲关游戏
RPA cloud computer, let RPA out of the box with unlimited computing power?
从服务器到云托管,到底经历了什么?
“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点
快速上手使用本地测试工具postman
Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
QT creator add custom new file / Project Template Wizard
C language 005: common examples
Go learning notes (1) environment installation and hello world
Fully automated processing of monthly card shortage data and output of card shortage personnel information
Two small problems in creating user registration interface
paddle入门-使用LeNet在MNIST实现图像分类方法二
Basic principle and usage of dynamic library, -fpic option context
如果在构造函数中抛出异常,最好的做法是防止内存泄漏?
An error is reported during the process of setting up ADG. Rman-03009 ora-03113