postman 用上一个请求的响应体中的字段设置下一个请求的请求参数

文章目录

    • Intro
    • [Postman usage](#Postman usage)
      • [`Pre-request Script`](#Pre-request Script)
      • `Tests`
    • [javascripts API](#javascripts API)

Intro

这一切都是为了增加自动化动作所占的比例(减少人手工操作复制粘贴可能会造成的错误)。

Postman usage

最常用的:选HTTP方法类型、写URL,在Headers中填请求头,在Body中填请求体。

Pre-request ScriptTests 是干什么用的?先看执行顺序:

Pre-request Script

https://learning.postman.com/docs/writing-scripts/pre-request-scripts/

Tests

https://learning.postman.com/docs/writing-scripts/test-scripts/

javascripts API

javascript 复制代码
// 获取某个环境变量
pm.environment.get("环境变量名")

// Tests 中获取 responseBody
var resp = pm.response.json();
// 把response中的某个字段设置到某个环境变量中
pm.environment.set("环境变量名", resp.XXX);

之后在其他请求中要引用这个environment的话,语法如下:

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-environment-variables-in-scripts

相关推荐
aiweker2 小时前
Selenium 使用指南:从入门到精通
python·selenium·测试工具
Future_yzx3 天前
Selenium 浏览器操作与使用技巧——详细解析(Java版)
java·selenium·测试工具
Algorithm-0073 天前
【Postman 接口测试】接口用例设计与评审
测试工具·postman
晚晚不晚4 天前
登录授权流程
postman
hunter2062064 天前
ubuntu无法上网的解决办法
网络·测试工具·ubuntu
霍格沃兹测试开发学社测试人社区5 天前
性能测试丨JVM 性能数据采集
软件测试·jvm·测试开发·测试工具
Algorithm-0075 天前
【Postman接口测试】Postman的全局变量和环境变量设置
测试工具·postman
安冬的码畜日常5 天前
【玩转 Postman 接口测试与开发2_009】第八章:利用 Postman 的 Flows 模块实现工作流测试(Workflow Testing)
测试工具·接口测试·postman·workflow·api接口·postman flows·工作流测试
Algorithm-0075 天前
【Postman接口测试】Postman的安装和使用
测试工具·postman
Lilixxs5 天前
使用 postman 测试思源笔记接口
笔记·测试工具·postman