如何在小黄瓜步骤中发送有效载荷和头部参数

时间:2016-10-17 01:24:55

标签: cucumber-jvm gherkin

黄瓜新手。 我想用黄瓜jvm测试休息api。

假设我有以下情况

scenario: 
 * POST at "http://localhost:8080/x" with payload: 
   """
     <user>
      <name>abc</name>
     </user>
   """
   with header:
   |param1|value|
   |param2|value|

但它没有用。

如果我将步骤分为2,一个给出有效载荷,另一个给出头, 我必须保持第一步(因为它会丢失标题)并执行第二步的实际后期操作。

我的选择是什么? 感谢

1 个答案:

答案 0 :(得分:0)

有一个feature request for supporting both tables and docstrings,但由于在所有黄瓜实施中支持它的工作量不同,它被关闭了,而不仅仅是jvm的那个。

因此,解决方法是将其拆分为多个步骤,收集所有数据,并在最后发送:

Scenario: Create a user
Given the following payload:
"""
<user><name>abc</name></user>
"""
And the following headers:
| param | value |
When the request is sent as "POST" to "http://example.com/users"
Then the user is created

我认为这也有助于方案的可读性,并且有效负载和标头都是可选的,这可能对其他(更简单的)请求有用。