Karate: Using data-driven embedded template approach for API testing

后端 未结 1 1919
野性不改
野性不改 2020-12-02 03:09

I want to write data-driven tests passing dynamic values reading from external file (csv). Able to pass dynamic values from csv for simple strings (account number & aff

相关标签:
1条回答
  • 2020-12-02 03:24

    CSV is only for "flat" structures, so trying to mix that with JSON is too ambitious in my honest opinion. Please look for another framework if needed :)

    That said I see 2 options:

    a) use proper quoting and escaping in the CSV

    b) refer to JSON files

    Here is an example:

    Scenario Outline:
    * json foo = foo
    * print foo
    
    Examples:
    | read('test.csv') |
    

    And test.csv is:

    foo,bar
    "{ a: 'a1', b: 'b1' }",test1
    "{ a: 'a2', b: 'b2' }",test2
    

    I leave it as an exercise to you if you want to escape double-quotes. It is possible.

    Option (b) is you can refer to stand-alone JSON files and read them:

    foo,bar
    j1.json,test1
    j2.json,test2
    

    And you can do * def foo = read(foo) in your feature.

    0 讨论(0)
提交回复
热议问题