我刚开始编写功能文件。我试图用json主体测试POST调用,但结果显示请求无效。我正试着把Json的数组发送到体内,肯定是体内遗漏了什么。下面是json主体和我为特性文件所写的内容。是否有其他方法将请求正文作为文件夹中的文件提供。
{
"paymentDetails":
[
{
"aaaaaa": "AAAAAAAAAA",
"bbbbbb": "BBBBBBBBBB",
"cccccc": "CCCCCCCCCC",
"dddddd": {
"ddddddd1": {
"dddddd1.2": {
"addressLine1": "abc ST",
"city": "BROOKLYN",
"state": "NY",
"zip": "123123",
"USAddress": true
}
}
},
"eeeeeee": "EEEEEEEE",
"fffffff": "FFFFFFFF",
"ggggggg": 29,
"hhhhhhh": {
"hhhhhh1": "NY",
"hhhhhh2": "10"
},
"iiiiiiii": true,
"jjjjjjjj": "123",
"kkkkkkkk": "3481",
"llllllll": 0
}
]
}
Scenario: POST Rest endpoint
Given a user with username "xxxxxx"
And a password of "zzzzzzzzzzzzzzz"
And a body with "aaaaaa" as "AAAAAAAAAA"
And a body with "bbbbbb" as "BBBBBBBBBB"
And a body with "cccccc" as "CCCCCCCCCC"
And a body with "dddddd.ddddddd1.dddddd1.2.addressLine1" as "abc ST"
And a body with "dddddd.ddddddd1.dddddd1.2.city" as "BROOKLYN"
And a body with "dddddd.ddddddd1.dddddd1.2.state" as "NY"
And a body with "dddddd.ddddddd1.dddddd1.2.zip" as 123123
And a body with "dddddd.ddddddd1.dddddd1.2.USAddress" as "true"
And a body with "eeeeeee" as "EEEEEEEE"
And a body with "fffffff" as "FFFFFFFF"
And a body with "ggggggg" as 29
And a body with "hhhhhhh.hhhhhh1" as "NY"
And a body with "hhhhhhh.hhhhhh2" as 10
And a body with "iiiiiiii" as "true"
And a body with "jjjjjjjj" as 123
And a body with "kkkkkkkk" as 3481
And a body with "llllllll" as 0
When a POST request is made to "https://..............."
Then log response body
And response code is 200
为了确保发送正确的json消息,您可以考虑创建域对象,并使用类似jackson的库将它们序列化为json。
此外,您可以使用构建器模式来填充对象上的必要字段。
有很多教程可以向你展示这是如何工作的。