如何在Gherkin的Scenario Outline中将Example表值嵌入到Json中

时间:2017-08-04 23:42:19

标签: json cucumber gherkin cucumber-java

Scenario Outline: I have an audit type <type>
    When a request is received
    """
    {
              "elements":{  
                 "type":<type>,
                 "id":"sku-1"
              }
    """
    Examples:
        |   type    |
        |   test1   |
        |   test2   |
        |   test3   |

如何用例子中给出的值替换上述问题?

2 个答案:

答案 0 :(得分:1)

最好不要为Json使用Doc String。相反,试试这个:

Scenario Outline: I have an audit type
    When a request is received of "<type>"

    Examples:
      | type  |
      | test1 |
      | test2 |
      | test3 |

很抱歉, Ruby 中的响应,不熟悉从String到Json对象或Hashtable 的 Java转换。但我发现这个more可能有助于管理json:

在Ruby中:

When(/^a request is received of "([^"]*)"$/) do |type|
  json = eval("{'elements':{'type':'#{type}','id':'sku-1'}}")
end

首次运行时,json将为:{'elements':{'type':'test1','id':'sku-1'}}

希望你能让它发挥作用。

答案 1 :(得分:0)

我用简单的改变

Scenario Outline: I have an audit type <type>
    When a request is received
    """
    {
              "elements":{  
                 "type":'<type>',
                 "id":"sku-1"
              }
    """
    Examples:
        |   type    |
        |   test1   |
        |   test2   |
        |   test3   |