在空手道场景大纲测试中,如何通过变量传递示例表中的参数值 [英] In Karate Scenario Outline test, how to pass param values in the Examples table through a variable

查看:22
本文介绍了在空手道场景大纲测试中,如何通过变量传递示例表中的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大多数 API 请求中使用相同的数据集,例如.日期范围 FromDate &迄今为止.但是,如果我想更改日期范围,那么我将不得不为所有场景大纲更改它.为了避免这种情况,我可以在背景部分定义日期范围吗?在场景大纲示例表中到处使用变量名称?空手道能做到吗?请帮忙.谢谢.

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.

功能:验证 API 是否正确返回了产品背景:* 配置 ssl = 真* url 'https://......'并且 def FromDate1 = '2019/06/27'并且 def ToDate1 = '2019/06/27'

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.

推荐答案

当然可以.因为定义为普通变量的更容易使用,所以您可以直接引用它而不是添加尖括号.

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

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

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

这篇关于在空手道场景大纲测试中,如何通过变量传递示例表中的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆