简体   繁体   English

在空手道场景大纲测试中,如何通过变量传递示例表中的参数值

[英]In Karate Scenario Outline test, how to pass param values in the Examples table through a variable

I am using same set of data in most of my API requests, for ex.我在大多数 API 请求中使用相同的数据集,例如。 date ranges FromDate & ToDate.日期范围 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'功能:验证 API 是否正确返回产品背景:* 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.我应该能够使用包含要在场景大纲中的示例表中使用的值的变量名称。

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 .请注意,在 0.9.3 版本之后,这种混淆得到了解决,即使对于Scenario Outline ,您也不再需要尖括号。 Please read: https://github.com/intuit/karate#scenario-outline-enhancements请阅读: https : //github.com/intuit/karate#scenario-outline-enhancements

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM