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

时间:2019-12-05 17:02:00

标签: 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" : "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

1 个答案:

答案 0 :(得分:1)

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

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

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

* print some

应打印值data