Neha Bagtharia
Neha Bagtharia

Reputation: 43

How can I call a variable from one feature file to another feature file using Karate API Testing

Feature: Add data

Scenario: Add unique data

Given url
And request {name: '#(name)', lastName: '#(lastName)'}
And method POST
Then status 200
And def res = response
And def newId = res.data.id

One id will be generated as soon as above api is called. I want to use the id generated in another file to update the data. I have stored the id in 'newId' variable. How can I use this variable and its value in another feature file?

Upvotes: 2

Views: 4518

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

This is explained in detail in the documentation - you should actually read it :)

So if you have a feature called.feature as follows:

Feature:

Scenario:
    * print newId

You can add this as the last line of the code you posted:

* call read('called.feature') { newId: '#(newId)' }

Upvotes: 1

Related Questions