1

我是编写功能文件的新手。我正在尝试使用 json body 测试 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 
4

1 回答 1

0

为了确保您发送正确的 json 消息,您可以考虑创建域对象并使用类似jackson的库将它们序列化为 json 。

此外,您可以使用构建器模式来填充对象上的必要字段。

有很多教程可以向您展示这是如何工作的。

于 2018-08-02T10:25:55.300 回答