Karate - Not able to run dynamic scenario outline in a loop

为君一笑 提交于 2019-12-24 10:23:14

问题


Here is my feature file , which just loads the json file and wants to iterate over the same

 Background:
 * def kittens = read('../json/test.json')
 Scenario Outline: cat name: <name>
 * print <name>
  Examples:
  | name |
  | kittens |

Here is the output

[
  {
    "name": "Bob"
  },
  {
    "name": "Wild"
  },
  {
    "name": "Nyan"
  },
  {
    "name": "Keyboard"
  },
  {
    "name": "LOL"
  },
  {
    "name": "Ceiling"
  }
]

As per my understanding this should run 7 times and give me individual variable values , But its running only once and giving me full json as output .

Let me know if I am missing anything.


回答1:


You are passing the list/array with a variable name in it, it will run only once as it interprets your entire json data as single variable name.

you could have noted it printed the entire data in your test.json once, as it acted as normal scenario outline.

You should pass the array directly as below to make it as dynamic scenario outline.

Feature: Dynamic Scenario Outline
 Background: 
  * def kittens = read('../json/test.json')
 Scenario Outline: cat name: <name> 
  * print <name> 
 Examples: 
  | kittens |

For dynamic scenario outline, the variables <name> will actually derived from your json, if there is key in your json as "name". Not as the header of the list in Examples:.

Karate docs- Dynamic Scenario Outline



来源:https://stackoverflow.com/questions/54397780/karate-not-able-to-run-dynamic-scenario-outline-in-a-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!