[英]How do i parameterize parameters i am passing in my API request & execute through Karate?
I am testing API's for my application & each API has multiple parameters to be passed, ex. 我正在为我的应用程序测试API,并且每个API都有多个要传递的参数,例如。 below:
下面:
https://abc.xyz.com/***.svc/restful/GetSummary?FromDate=2019/06/28&ToDate=2019/06/28&CompAreaId=15&RegId=4
Each parameter in the request has multiple values (within a defined set of values), so if I want to parameterize each parameter with all the values it could possibly have, how can I create a scenario that will help me achieve this? 请求中的每个参数都具有多个值(在一组定义的值内),因此,如果我想用可能具有的所有值对每个参数进行参数化,那么我该如何创建一种方案来帮助我实现这一目标?
I would appreciate any hints/views. 我将不胜感激任何提示/意见。
I have been passing parameters as shown in the code below, but unable to pull off the scenario above mentioned, it would be time-consuming & repetitive to pass parameters in a separate scenario each time. 我一直在传递参数,如下面的代码所示,但是无法完成上述方案,每次在一个单独的方案中传递参数将非常耗时且重复。
Scenario: Verify if GetContext API returns data with params 场景:验证GetContext API是否返回带参数的数据
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
You can use “Scenario Outline” to achieve that. 您可以使用“方案大纲”来实现。 The following modified code below will run for the 3 rows in the example.
下面的修改后的代码将在示例中的3行运行。 (related link: https://github.com/intuit/karate#the-cucumber-way )
(相关链接: 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 |
Instead of a static count, if you have a dynamic number of rows, you can store the parameter values in a json or CSV and reference it in the example. 如果行数是动态的,则可以使用静态值代替静态计数,可以将参数值存储在json或CSV中,并在示例中进行引用。 (related link: https://github.com/intuit/karate#dynamic-scenario-outline )
(相关链接: https : //github.com/intuit/karate#dynamic-scenario-outline )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.