如何参数化我在 API 请求中传递的参数并通过空手道执行?

How do i parameterize parameters i am passing in my API request & execute through Karate?

我正在为我的应用程序测试 API,每个 API 都有多个参数要传递,例如。以下:

https://abc.xyz.com/***.svc/restful/GetSummary?FromDate=2019/06/28&ToDate=2019/06/28&CompAreaId=15&RegId=4

请求中的每个参数都有多个值(在一组定义的值中),所以如果我想用它可能具有的所有值来参数化每个参数,我该如何创建一个场景来帮助我实现这个?

我将不胜感激 hints/views。

我已经按照下面的代码传参了,但是无法完成上面提到的场景,每次都在单独的场景中传参,既费时又重复。

场景:验证 GetContext API returns 数据是否带有参数

Given path 'GetContext'
And param FromDate = '2019/06/27'
And param ToDate = '2019/06/27'
And param CompAreaId = 20
And param RegId = 4
When method get
Then status 200
* def res = response
* print 'response:', response

您可以使用“场景大纲”来实现。以下修改后的代码将为示例中的 3 行 运行。 (相关link:https://github.com/intuit/karate#the-cucumber-way)

Scenario Outline:
Given path 'GetContext'
And param FromDate = '<FromDate>'
And param ToDate = '<ToDate>'
And param CompAreaId = <CompAreaId>
And param RegId = <RegId>
When method get
Then status 200
* def res = response
* print 'response:', response

  Examples:
    | FromDate   | ToDate      | CompAreaId | RegId |
    | 2019/06/27 | 2019/06/27  | 20         | 4     |
    | 2019/06/28 | 2019/06/28  | 21         | 5     |
    | 2019/06/29 | 2019/06/29  | 22         | 6     |

如果您有动态的行数,而不是静态计数,您可以将参数值存储在 json 或 CSV 中,并在示例中引用它。 (相关link:https://github.com/intuit/karate#dynamic-scenario-outline)