我需要将数据从一个功能文件传递到另一个功能文件。
功能(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/