Reputation: 101
I am using same set of data in most of my API requests, for ex. date ranges FromDate & ToDate. However, if i wish to change the date range then i will have to change it for all the Scenario Outlines. To avoid this, can i define the date ranges in the background section & use the variable name all over in Scenario Outline Examples tables? Can that be done in karate? Please help. Thanks.
Tried many ways but unable to pull if off somehow.
Feature: Verify that products are properly returned by the API Background: * configure ssl = true * url 'https://......' And def FromDate1 = '2019/06/27' And def ToDate1 = '2019/06/27'
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 |
| FromDate1 | 2019/06/27 | 20 | 4 |
| 2019/06/28 | 2019/06/28 | 21 | 5 |
| 2019/06/29 | 2019/06/29 | 22 | 6 |
I should be able to use the variable names that contain the value to be used in the Examples table in Scenario Outline.
Upvotes: 2
Views: 5932
Reputation: 58058
Yes of course. Because what is defined as a normal variable is even easier to use, you refer to it directly instead of adding angle-brackets.
You need to make this small change:
And param FromDate = FromDate1
And param ToDate = ToDate1
Note that in version 0.9.3 onwards this confusion is addressed, you don't need the angle-brackets any more even for the Scenario Outline
. Please read: https://github.com/intuit/karate#scenario-outline-enhancements
Upvotes: 3