1

I am testing API's for my application & each API has multiple parameters to be passed, ex. 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

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
Ravi B
  • 1,574
  • 2
  • 14
  • 31
Shrikant
  • 91
  • 1
  • 7

1 Answers1

2

You can use “Scenario Outline” to achieve that. The following modified code below will run for the 3 rows in the example. (related 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     |

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. (related link: https://github.com/intuit/karate#dynamic-scenario-outline)

Neodawn
  • 1,086
  • 1
  • 6
  • 9
  • Another question though; what if i want to define/declare values for the **FromDate** & **ToDate** parameters at the very beginning of the features file, so that, if i want to change the date range as per my need, i will have to change it just at the beginning & not for each Scenario Outline. – Shrikant Jun 29 '19 at 08:20