空手道-无法在循环中运行动态方案大纲 [英] Karate - Not able to run dynamic scenario outline in a loop

查看:36
本文介绍了空手道-无法在循环中运行动态方案大纲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的功能文件,该文件仅加载json文件,并希望在同一文件上进行迭代

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 |

这是输出

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

根据我的理解,这应该运行7次并为我提供单独的变量值,但是它仅运行一次并给我完整的json作为输出.

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.

推荐答案

您正在传递带有变量name的列表/数组,它将仅运行一次,因为它将整个json数据解释为单个变量.

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.

您可能已经注意到它将所有数据打印在test.json中 一次,因为它是正常情况下的轮廓.

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 |

对于动态场景概述,如果json中的键为"name",则变量<name>实际上将从json派生.不能作为Examples:中列表的标题.

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:.

空手道文档-动态场景大纲

这篇关于空手道-无法在循环中运行动态方案大纲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆