这是我目前的框架结构
CreateDiscount.feature
Discount_Payload.json
SearchDiscount.feature
Search_Payload.json
这是每个文件中代码的外观 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
{
"code": "ND12",
"name": "NDS coupon Testing",
"description": "NDS coupon testing via postman",
"operator": "EQ"
}
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 值,这很好
但是现在当我想在SearchDiscount.feature中运行单独的测试用例时 为此,我也想从SearchDiscount.feature中更新Discount_Payload.json的名称和说明的值。
答案 0 :(得分:0)
您可以将值传递给正在调用的功能文件
与其在您要重用的要素中读取json,不如将其作为变量的输入传递给变量。
SearchDiscount.feature
* def discountInput = read('Discount_Payload.json')
* def createDiscount = call read('CreateDiscount.feature' ) {'changes' :'#(discountInput)'}
现在,您无需阅读CreateDiscount.feature中的输入内容
删除
* def changes = read('Discount_Payload.json')
来自您的CreateDiscount.feature
您可以在将其传递给可重复使用的功能之前,在呼叫功能中更改所需的任何值。
编辑:如果要针对不同的值运行此命令,则可以使用方案大纲并将值设置为discountInput,然后再将其传递给功能。
请参阅空手道说明文件。
https://github.com/intuit/karate#data-driven-features
编辑2: 方案针对您的问题的大纲示例。
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' |
现在,该场景将使用示例中提供的这两组值运行。