Karate Api Testing - How to pass data from one fea

2020-03-26 09:34发布

问题:

I need to pass data from one feature file to another.

Feature(1): Create a new user

Background:

* 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

Feature(2): Call newUser from feature 1

Background:

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

回答1:

Please read the docs: https://github.com/intuit/karate#calling-other-feature-files

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

And in one.feature you can get access to the JSON "argument"

* print some

Which should print the value data