简体   繁体   中英

Karate Api Testing - How to pass data from one feature file to another

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM