文章目录
- Intro
- Postman usage
- `Pre-request Script`
- `Tests`
- javascripts API
Intro
这一切都是为了增加自动化动作所占的比例(减少人手工操作复制粘贴可能会造成的错误)。
Postman usage
最常用的:选HTTP方法类型、写URL,在Headers中填请求头,在Body中填请求体。
Pre-request Script
和 Tests
是干什么用的?先看执行顺序:
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
// 获取某个环境变量
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