如何将变量从一个功能文件传递到另一个功能文件 [英] How can I pass a variable from one feature file to other
问题描述
在功能文件的一种情况下,我有一个变量,我需要在第二个功能文件的请求正文中使用该变量.
I have a variable in one of the scenario of a feature file which I need to use in the request body of second feature file.
For Example:
A.feature
Scenario: Test
Given url 'abc'
* def number = 12345
And request {tyu:'#(number)',dhd:'lkj'}
When method put
Then status 200
B.feature
Scenario: Test2
Given url 'pqr'
And request {tyu:'#(number)'}
When method put
Then status 200
注意:A.feature中的数字变量是一个6位数字,每次都会随机生成,并且应在B.feature文件中传递相同的数字.
Note: Number variable in A.feature is a 6 digit number which is randomly generated everytime and the same should be passed in B.feature file.
推荐答案
通常,如果您有两个相互依赖的Scenario
-s,则必须将它们组合为一个.请在此处参考文档: https://github.com/intuit/karate#script-structure
Normally if you have two Scenario
-s that depend on one another you have to combine them into one. Refer the docs here: https://github.com/intuit/karate#script-structure
但是,如果您确实在寻找如何初始化某些东西并在所有功能文件中重复使用它,也许您正在寻找karate.callSingle()
:
But if you are really looking for how to initialize something and re-use it across all feature files, maybe you are looking for karate.callSingle()
: https://github.com/intuit/karate#hooks
var result = karate.callSingle('get-token.feature');
这篇关于如何将变量从一个功能文件传递到另一个功能文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!