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

相关推荐
Wpa.wk4 小时前
性能测试-性能监控相关命令-基础篇
android·linux·运维·经验分享·测试工具·性能测试·性能监控
半路_出家ren4 小时前
20.基于Selenium实现界面自动化控制
运维·python·selenium·测试工具·网络安全·自动化·chromedriver
2401_832298105 小时前
Serverless全栈架构,云服务器运维效率革命
postman
猿饵块16 小时前
tcp--抓包--wireshark
网络·测试工具·wireshark
极客先躯19 小时前
老版本Postman请求脚本编写指南:从Async/Await到回调函数的完整迁移方案
测试工具·lua·postman
程序员三藏1 天前
软件测试环境搭建及测试过程
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
程序员杰哥1 天前
2026软件测试面试宝典(含答案+文档)
自动化测试·软件测试·python·测试工具·面试·职场和发展·测试用例
CCPC不拿奖不改名1 天前
基于FastAPI的API开发(爬虫的工作原理):从设计到部署详解+面试习题
爬虫·python·网络协议·tcp/ip·http·postman·fastapi
李昊哲小课1 天前
Selenium 自动化测试教程
爬虫·selenium·测试工具