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   |

How to solve the above problem to replace with the values given in Examples?

Digital
  • 495
  • 6
  • 22

2 Answers2

1

Might be better not to use Doc String for JSON. Instead try this:

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

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

Sorry, the response in in Ruby, not familiar with Java conversion from String to JSON object or Hashtable. I did however find this resource that might help to manage handle the JSON:

In Ruby:

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

First time this runs, json will be: {'elements':{'type':'test1','id':'sku-1'}}

double-beep
  • 4,567
  • 13
  • 30
  • 40
Daniel Fintinariu
  • 2,573
  • 1
  • 12
  • 16
0

I got it worked with simple change

Scenario Outline: I have an audit type <type>
    When a request is received
    """
    {
              "elements":{  
                 "type":'<type>',
                 "id":"sku-1"
              }
    """
    Examples:
        |   type    |
        |   test1   |
        |   test2   |
        |   test3   |
Digital
  • 495
  • 6
  • 22
  • Yes, you just needed to surround `` with `''` . Still it would be better to keep feature files for business behavior and coding for the steps :) – Daniel Fintinariu Aug 05 '17 at 01:02