在Postman JSON测试脚本中设置多个变量 [英] setting multiple variables in Postman JSON test scrip

查看:552
本文介绍了在Postman JSON测试脚本中设置多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容

let bodyData = pm.response.json()

let country = bodyData[0].Country

console.log(country)

pm.environment.set("country", country)

但我想设置多个变量。我的环境中大约有8个不同的变量,我尝试了以下操作,但它不起作用

but i want to set multiple variables. I have around 8 different variables in my environment and i tried the below but it doesnt work

let bodyData = pm.response.json()

let country = bodyData[0].Country
let postcode = bodyData[0].Postcode

console.log(country,postcode)

pm.environment.set("country","postcode", country, postcode)

感谢任何帮助

推荐答案

您需要创建单独的 .set()语句来捕获和重用其他请求中的不同变量。

You would need to create separate .set() statements to capture and reuse the different variables in other requests.

pm.environment.set("country", country)
pm.environment.set("postcode", postcode)

这篇关于在Postman JSON测试脚本中设置多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆