【问题标题】:How can I pass a variable from one feature file to other如何将变量从一个功能文件传递到另一个
【发布时间】:2018-11-28 10:36:56
【问题描述】:

我在功能文件的一种场景中有一个变量,我需要在第二个功能文件的请求正文中使用它。

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 中的 number 变量是一个 6 位的数字,每次随机生成,B.feature 文件中应该传入相同的数字。

【问题讨论】:

    标签: rest karate


    【解决方案1】:

    通常,如果您有两个相互依赖的Scenario-s,您必须将它们合并为一个。请参阅此处的文档:https://github.com/intuit/karate#script-structure

    但如果您真的在寻找如何初始化某些东西并在所有功能文件中重新使用它,也许您正在寻找karate.callSingle()https://github.com/intuit/karate#hooks

    var result = karate.callSingle('get-token.feature');
    

    【讨论】:

    • karate.callSingle() 完成了这项工作,事实上,使用这种方法可以减少我的每个功能文件中的几行代码。非常感谢@Peter
    猜你喜欢
    • 2021-05-25
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    相关资源
    最近更新 更多