【发布时间】:2020-06-05 13:53:45
【问题描述】:
我们正在使用 Rest Assure 自动化 REST API,其中请求 json 中的某些属性值需要在运行时替换,在某些情况下可以是 String,在其他情况下可以是 Integer。
请求 json:
{
"bInfo":{
"bEx":9, //Need to replace Integer value here
"oriDate":"2020-07-08"
},
"education":{
"educationE":{
"proCal":9, //Need to replace Integer value here
"cutAmt":250, //Need to replace Integer value here
"totalAmt":20 //Need to replace Integer value here
},
"educationInfo":{
"educationPur":"purtest", //Need to replace String value here
"educationStr":"Mu",
"educationPro":"RT",
"rec":"N",
"oriDate":"2019-08-10"
}
},
"educationRes":{
"pTest": "", //Set String value here
"rTest":"",
"sFl":""
},
"educationRResult":{
"as":""
},
"qualities":[{
"qualitiesE":{
"gt":10, //Need to replace Integer value here
"oValue":10,
"pPr":10,
"oVa":7,
"cIn":1,
"rRatio":2
}
},
{
"qualitiesE":{
"gt":1000,
"oValue":10,
"pPr":2,
"oVa":5,
"cIn":200,
"rRatio":1
}
},
{
"qualitiesE":{
"gt":70,
"oValue":25,
"pPr":100,
"oVa":7,
"cIn":40,
"rRatio":5
}
}]
}
用于替换字符串的代码:“dummyvalue”
request.replace("dummyvalue", "Test123");
O/P:成功运行。值替换为 Test123
同样在同一个json中需要用Integer替换value:xyz value 50
request.replace works only with String, if want to replace as Integer value tried
Declared String value = "50" as String and Tried
然后它将字符串值替换为“50”,因此发布时的请求失败,因为 json 有效负载期望该值为整数 50。如果尝试如下:
int amtIntValue = Integer.parseInt(50);
Then request.replace won't work
【问题讨论】:
标签: json rest-assured