karatedslautomation-testing

Data driven in Karate with multiple columns along with karate.setup() is Possible?


Can I validate multiple values in the response when use path from each element in array while I am using @setup in Karate framework. In example I can pass as many as columns and validate them with response.

Please refer the following snippet for more details

`Feature:

@setup Scenario: * def data = [ { id: 1 }, { id: 2322 }, { id: 33 } ]

Scenario Outline: * url 'https://httpbin.org/anything' * path id * method get

Examples:
  |id                   |StatusCode|ResponseMessage| 
  | karate.setup().data |200       |Ok             |`

Solution

  • Yes, all JSON keys in the data will be converted into "columns", here is an example, try it:

    Feature:
    
    @setup
    Scenario:
    * def data = [{ id: 1, code: 200}, { id: 2, code: 200}]
    
    Scenario Outline: id: ${id}
    * url `https://httpbin.org/anything/${id}`
    * method get
    * match responseStatus == code
    
    Examples:
    | karate.setup().data |
    

    Karate supports the built-in variable responseStatus: https://github.com/karatelabs/karate#responsestatus

    Response Message is typically never needed.