postman内置脚本说明
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,.内置脚本说明 1. 清除一个全局变量 Clear a global variable 对应脚本: postman.clearGlobalVariable("variable_ke
千家信息网最后更新 2025年12月02日postman内置脚本说明
.内置脚本说明
1. 清除一个全局变量 Clear a global variable 对应脚本: postman.clearGlobalVariable("variable_key"); 参数:需要清除的变量的key 2.清除一个环境变量 Clear an environment variable 对应脚本: postman.clearEnvironmentVariable("variable_key"); 参数:需要清除的环境变量的key 3.response包含内容 Response body:Contains string 对应脚本: tests["Body matches string"] =responseBody.has("string_you_want_to_search"); 参数:预期内容 4.将xml格式的response转换成son格式 Response body:Convert XML body to a JSON Object 对应脚本: var jsonObject = xml2Json(responseBody); 参数:(默认不需要设置参数,为接口的response)需要转换的xml 5.response等于预期内容 Response body:Is equal to a string 对应脚本: tests["Body is correct"] = responseBody === "response_body_string"; 参数:预期response 6.json解析key的值进行校验 Response body:JSON value check 对应脚本: tests["Args key contains argument passed as url parameter"] = 'test' in responseJSON.args 参数:test替换被测的值,args替换被测的key 7.检查response的header信息是否有被测字段 Response headers:Content-Type header check 对应脚本: tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); 参数:预期header 8.响应时间判断 Response time is less than 200ms 对应脚本: tests["Response time is less than 200ms"] = responseTime < 200; 参数:响应时间 9.设置全局变量 Set an global variable 对应脚本: postman.setGlobalVariable("variable_key", "variable_value"); 参数:全局变量的键值 10.设置环境变量 Set an environment variable 对应脚本: postman.setEnvironmentVariable("variable_key", "variable_value"); 参数:环境变量的键值 11.判断状态码 Status code:Code is 200 对应脚本: tests["Status code is 200"] = responseCode.code != 400; 参数:状态码 12.检查code name 是否包含内容 Status code:Code name has string 对应脚本: tests["Status code name has string"] = responseCode.name.has("Created"); 参数:预期code name包含字符串 13.成功的post请求 Status code:Successful POST request 对应脚本: tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202; 14.微小验证器 Use Tiny Validator for JSON data 对应脚本: var schema = { "items": { "type": "boolean" } }; var data1 = [true, false]; var data2 = [true, 123]; console.log(tv4.error); tests["Valid Data1"] = tv4.validate(data1, schema); tests["Valid Data2"] = tv4.validate(data2, schema); 参数:可以修改items里面的键值对来对应验证json的参数
脚本
参数
变量
内容
环境
全局
时间
格式
状态
检查
验证
微小
成功
信息
字段
字符
字符串
接口
验证器
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
我的世界游戏里有哪些多人服务器
根服务器被攻击
服务器cpu家用合适吗
互联网基金科技投资
计算机网络技术不会英语
服务器至强cpu几核
数据库原理与sql题库
一个千万级数据库查找效率
服务器机箱4u
传奇什么时候开服务器好
网络安全保障的第一责任人
复制数据库代码
红黑人口数据库2010
称重打码数据库
软件开发公司的技术优势
java数据加入数据库
思讯数据库ip地址怎么看
网络安全预防两易
计算机网络安全基本概念
腾讯政企云网络安全
网络安全售前工程师工资高吗
上海电商软件开发要多少钱
邮件是存储在服务器吗
网络安全大会2018
软件开发专业单招面试问题
手势数据库
我的世界服务器怎么搭桥模式
十年互联网科技公司
网络安全政策法律动态
中北大学网络安全就业