POST休息呼叫的小黄瓜功能文件

时间:2018-07-30 15:01:18

标签: cucumber gherkin feature-file

我刚开始编写功能文件。我正在尝试使用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 

1 个答案:

答案 0 :(得分:0)

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

此外,您可以使用builder pattern来填充对象上的必要字段。

那里有很多教程,向您展示这是如何工作的。