如何为每次执行json数组循环调用其他功能

时间:2019-03-12 10:17:14

标签: arrays json karate

    * def runOperation1 = read('classpath:ic/common/resources/operation/runOperation.feature')
* def operationInputData = read('classpath:ic/feature/streaming/TestData/operationData.json')
* def result = call runOperation1 operationInputData
 * def AllResponse = $result[*].response
 * print AllResponse

在完成json数组的所有执行后,将在此处填充“ AllResponse”。 对于每个json数组,我们需要调用其他功能并声明一些值。然后我们需要遍历json数组中的另一个元素

1 个答案:

答案 0 :(得分:2)

我看到了两种解决方法,

1,在您的runOperation.feature

中添加调用另一个功能和声明的附加步骤

2,而不是callrunOperation.feature中的场景创建动态场景大纲,并在该场景中添加您的呼叫步骤

编辑:

假设operationData.json

[
 {"name": "Johan"}, 
 {"name": "Ben"}
]

runOperation.feature假定为

Feature: run operation feature
 Scenario: run operation Scenario
     Given url "http://httpbin.org/get"
     And path name
     And method get
     And status 200

anothercall.feature假定为

Feature: another call feature
 Scenario: another call scenario
     Given url "http://httpbin.org/get"
     And path name
     And method delete
     And status 200

现在您可以使用当前功能了,

Background:
  * def operationInputData = read('classpath:ic/feature/streaming/TestData/operationData.json')

Scenario Outline:
  # steps from runoperation.feature
  Given url "http://httpbin.org/get"
  And path <name>
  And method get
  And status 200
  # calling another feature
  Then def anotherCall = call read("anothercall.feature") {"name": <name>}
  # match / assert condition
 Examples:
 |operationInputData|

我建议选择第二个选项,因为第一个选项可能导致不必要的并发症。