How to iterate each row in example section based on static data

Viewed 136

Requirement: I want to iterate each row in example section on the basis of a field (ProductType) present in input Json.

ProductType can have value 11 or 22 or 33. But expectedAmount for those should be same. I am giving a snippet below-

**Feature:** To check expected results for different values of ProductType

  Background: 
    * url http://localhost:8080
    * header Content-Type = 'application/json'

  Scenario Outline: To check expected results for different values of ProductType
    Given path PATH
    And request <data>
    When method POST
    Then status 200
    And match $.Parent[0].Amount ==  expectedAmount>
Examples: 
  | data                                                 | ExpectedAmount |
  | read('classpath:' + INPUT_JSON_PATH + '/Test1.json') |        1234.56 |
  | read('classpath:' + INPUT_JSON_PATH + '/Test2.json') |        6789.12 |
  | read('classpath:' + INPUT_JSON_PATH + '/Test3.json') |        3453.56 |

Json Input:

{
      "Parent" : [ {
      "Id" : "1",
      "productType" : 11
      }]

}

Can you please suggest a solution for it?

Thanks, Abhi

1 Answers

The Examples: rows do not support any variable evaluation e.g. read('classpath:' + INPUT_JSON_PATH + '/Test1.json') so please do this instead:

* def data = read('classpath:' + INPUT_JSON_PATH + '/' + file)

Examples: 
  | file       | ExpectedAmount |
  | Test1.json |        1234.56 |
  | Test2.json |        6789.12 |
  | Test3.json |        3453.56 |

I'm not reading the rest of your question because I still don't understand it.

Related