简体   繁体   English

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

[英]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.

相关问题 如何仅通过在请求中传递特定参数来获取特定参数? SpringBoot API - How could I get specific parameters just by passing them in the request? SpringBoot API 在空手道中,如何从另一个请求中的一个请求发送响应 cookie - In Karate how do I send response cookie from one request in another request 如何通过 Node API 正确路由数据? - How do I properly route data through my Node API? 如何在REST api中捕获请求url / domain? - How do I catch the request url / domain in my REST api? 如何获得我的API请求以获取更新的数据库? - How do I get my API request to grab the updated Database? 如何修复我的 api 项目的 429 请求错误? - How do I fix a 429 request error for my api project? 我需要在空手道 api 测试中验证请求超时 - I need to validate request time out in karate api testing 如何使用apache httpClient API将文件+ api密钥和其他参数作为单个请求发送? - How do I use the apache httpClient API to send file + api key and other parameters as a single request? 详细信息在我的请求中可见,如何在我的 API 请求中过滤它? - Details are visible in my request, how do I filter this in my API request? 如何将我的结构正确格式化为我正在使用的 API? - How do I correctly format my structures to the API I am using?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM