2

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
Mark Hughes
  • 73
  • 1
  • 5

1 Answers1

2

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Hi Peter, thanks for the response. I've tried the above and as a result of calling one.feature I end up with 2 new users. I would like one.feature to POST a new user and pass the response to two.feature where I can verify the user was created. – Mark Hughes Dec 05 '19 at 17:52
  • @MarkHughes sorry I can't understand - maybe someone else has a better answer for you, all the best. I really think you haven't understood the docs and examples if you have already gone through them – Peter Thomas Dec 05 '19 at 17:54
  • I'm simply trying to pass data from feature to another .... maybe I don't understand your documentation but that response should be your answer for everything. – Mark Hughes Dec 05 '19 at 17:56
  • @MarkHughes see my edit. and read the docs. I have nothing more to add. all the very best – Peter Thomas Dec 05 '19 at 17:57
  • @MarkHughes The callfeature demo at the following link should be helpful: https://github.com/intuit/karate/tree/master/karate-demo/src/test/java/demo/callfeature – Neodawn Dec 06 '19 at 08:56
  • Thanks, that fixed it – Mark Hughes Jan 15 '20 at 15:07