api - Karate Api 测试 - 如何将数据从一个功能文件传递到另一个功能文件

标签 api testing automation karate

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

功能(1):创建新用户

背景:

* url 'http://127.0.0.1:8900/'
* header Accept = 'application/json'
Scenario: Create a new user
 Given path '/user'
 And request {"email" : "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f0e1f7f0c4f0e1f7f0aae7ebe9" rel="noreferrer noopener nofollow">[email protected]</a>", "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

最佳答案

请阅读文档: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

关于api - Karate Api 测试 - 如何将数据从一个功能文件传递到另一个功能文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59199992/

相关文章:

从变量获得的 javascript 正则表达式在测试 : "is not a function" 时给出错误

linux - 有关在文章/Web 2.0 网站上创建帐户/发帖的自动化过程的帮助

javascript - 根据嵌套数组中匹配的键值获取对象

java - 收到致命警报 : handshake_failure webservice

testing - 在没有 UI 交互的情况下设置值。 Cypress 应用程序操作

python - 使用python将变量传递给bash命令

java - 从 testNG 测试中检索 @Test 描述

api - Azure HBASE REST - colfam :col 的简单获取失败

javascript - 将字节数组输出转换为 Blob 损坏文件

java - Micronaut 和 JUnit 回滚