【问题标题】:Karate Api Testing - How to pass data from one feature file to another [duplicate]空手道 Api 测试 - 如何将数据从一个功能文件传递到另一个 [重复]
【发布时间】:2020-03-30 16:06:07
【问题描述】:

我需要将数据从一个功能文件传递到另一个。

功能(1):创建新用户

背景:

* url 'http://127.0.0.1:8900/'
* header Accept = 'application/json'
Scenario: Create a new user
 Given path '/user'
 And request {"email" : "test@test.com", "name" : "Brian"}
 When method post
 And def newUser = $..id
 Then status 201

功能(2):从功能 1 调用 newUser

背景:

* url 'http://127.0.0.1:8900/'
* header Accept = 'application/json'
 Scenario: Call User
  * def newUser = $..id
  * print newUser

【问题讨论】:

    标签: api testing automation karate


    【解决方案1】:

    请阅读文档:https://github.com/intuit/karate#calling-other-feature-files

        * def aVariable = "can be anything"
        * def result = call read('one.feature') { some: 'data', useExpression: #(aVariable) }
    

    one.feature 中,您可以访问 JSON“参数”

    * print some
    

    应该打印值data

    【讨论】:

    • 嗨,彼得,感谢您的回复。我已经尝试了上述方法,并且由于调用 one.feature 我最终得到了 2 个新用户。我希望 one.feature 发布一个新用户并将响应传递给 two.feature,我可以在其中验证用户是否已创建。
    • @MarkHughes 抱歉,我无法理解 - 也许其他人有更好的答案给你,祝你好运。如果您已经阅读过文档和示例,我真的认为您还没有理解它们
    • 我只是想将数据从功能传递到另一个....也许我不理解您的文档,但该响应应该是您对所有问题的答案。
    • @MarkHughes 看到我的编辑。并阅读文档。我没有什么要补充的了。万事如意
    • @MarkHughes 以下链接中的通话功能演示应该会有所帮助:github.com/intuit/karate/tree/master/karate-demo/src/test/java/…
    猜你喜欢
    • 1970-01-01
    • 2021-02-02
    • 2019-04-16
    • 1970-01-01
    • 2019-02-03
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    相关资源
    最近更新 更多