空手道-如何在内部调用的功能文件中设置特定值 [英] karate - How to set specific values in a feature file which is called internally

查看:71
本文介绍了空手道-如何在内部调用的功能文件中设置特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前的框架结构

CreateDiscount.feature
Discount_Payload.json
SearchDiscount.feature
Search_Payload.json

这是每个文件中代码的外观 CreateDiscount.feature

This is how the code in each file looks CreateDiscount.feature

Scenario: Create a discount
* def changes = read('Discount_Payload.json')
* set changes.code = cu.getCouponCode(4)
* set changes.operator = 'LT'
Given url baseUrl + CREATE_DISCOUNT
And request changes
When method post
Then status 200

Discount_Payload.json

Discount_Payload.json

{
"code": "ND12", 
"name": "NDS coupon Testing",
"description": "NDS coupon testing via postman",
"operator": "EQ"
}

SearchDiscount.feature

SearchDiscount.feature

Scenario: Create a discount and search it
* def createDiscount = call read('CreateDiscount.feature') 
* print createDiscount
* def coupon_code = createDiscount.changes.code
* print coupon_code
* def changes = read('Search_Payload.json')
* set changes.coupon_code = coupon_code
Given url baseUrl + SEARCH
And request changes
When method post
Then status 200

Search_Payload.json
{
 "mode" : "Browse",
 "coupon_code" : "abrakadabra"
}

因此,当前,每当我运行SearchDiscount.feature时,它将在内部调用CreateDiscount.feature,如果我在创建折扣时仅设置 code operator 值,则很好

So currently whenever I run SearchDiscount.feature , It internally calls CreateDiscount.feature , This is fine if I have only code and operator values to be set while creating discount.

但是现在当我想在SearchDiscount.feature中运行单独的测试用例时 为此,我也想从SearchDiscount.feature中更新Discount_Payload.json的名称说明的值.

But now when I want to run separate test case in SearchDiscount.feature for which I want to update the value of name and description of Discount_Payload.json also from SearchDiscount.feature.

推荐答案

您可以将值传递给要调用的功能文件

You can pass values to feature file that you are calling

与其在您要重用的要素中读取json,不如将其作为变量的输入传递给变量.

Instead of reading a json in you feature which you want to reuse, pass that json in a variable as an input to your feature.

SearchDiscount.feature

SearchDiscount.feature

* def discountInput = read('Discount_Payload.json')
* def createDiscount = call read('CreateDiscount.feature' ) {'changes' :'#(discountInput)'}

现在,您无需阅读CreateDiscount.feature中的输入内容

Now you don't need to read for input in your CreateDiscount.feature

删除

 * def changes = read('Discount_Payload.json')

来自您的CreateDiscount.feature

from your CreateDiscount.feature

您可以在将其传递给可重复使用的功能之前,在呼叫功能中更改所需的任何值.

you can change whatever values you want in your calling feature before passing it to your reusable feature.

编辑:如果要针对不同的值运行此命令,则可以使用方案大纲并将值设置为discountInput,然后再将其传递给功能.

EDIT: If you want to run this for different values you can use scenario outline and set values to your discountInput before passing it to your feature.

请参阅空手道说明文件.

please refer karate documentation.

https://github.com/intuit/karate#data-driven-features

方案针对您的问题的大纲示例.

EDIT 2: Scenario Outline sample for your question.

Scenario Outline:
    * def discountInput = read('Discount_Payload.json')
    * set discountInput.name = <name>
    * set discountInput.description = <description>
    * def createDiscount = call read('CreateDiscount.feature' ) {'changes' :'#(discountInput)'}
Examples:
    |   name  |   description  |
    |   'A'   |      'Ades'    |
    |   'B'   |      'Bdes'    |

现在该场景将使用示例中提供的这两组值运行.

now the scenario will run with these 2 set of values provided in the examples.

这篇关于空手道-如何在内部调用的功能文件中设置特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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