如何在 response 取值,然后用作请求
还请大佬们不吝赐教。这是个自动化测试场景,类似于我们注册 app,比如需要填下住址,可以参考下边的接口返回值,我需要随机提取一组数据比如"value":"abc"、"value":"D",用作下一步的请求体,我该怎么提取,困扰小弟半天了。
{
"status":{
"code":0,
"detail":"",
"serverResponseTime":1616569995778
},
"body":[
{
"label":"abc",
"value":"abc",
"children":[
{
"label":"D",
"value":"D"
},
{
"label":"E",
"value":"E"
},
{
"label":"F",
"value":"F"
}
]
},
{
"label":"qwe",
"value":"qwe",
"children":[
{
"label":"R",
"value":"R"
},
{
"label":"T",
"value":T"
},
{
"label":"Y",
"value":"Y"
}
]
},
}欢迎各路大佬来此评论
如果你使用python测试的话 可以先把body拿出来存成list 去len这个list的长度 随机一个不大于len长度的整数n之后就是取随机数(index)的内容和值
代码大概长这样:
import random
body = [{"label":1,"value":2,"children":[{"label":1,"value":2}]},
{"label":7,"value":8,"children":[{"label":9,"value":10}]}]
lens = len(body)
r_num = random.randint(0,lens-1)
label = body["label"]
value = body["value"]
children = body["children"]
其他语言 逻辑一样(我这只是个demo 你得按照需求自己改代码) https://testerhome.com/topics/29210参考下这篇文章 循环吧
页:
[1]