Ashok kumar Ganesan
Ashok kumar Ganesan

Reputation: 1128

Karate: How can we retrieve the value from called feature file

I have two parameter in feature file A and I pass those values to another feature file called B.

But I am unable to retrieve the values as expected in Feature file B

CODE:

Feature File A:

And def Response = response
And def token = response.metaData.paging.token
And def totalPages = response.metaData.paging.totalPages

* def xyz = 
"""
  function(times){
    for(currentPage=1;currentPage<=times;currentPage++){
      karate.log('Run test round: '+(currentPage));
      karate.call('ABC.feature', {getToken:token, page:currentPage});

    }
    java.lang.Thread.sleep(1*1000);
  }
"""
* call xyz totalPages 

Feature File B:

* def token = '#(getToken)'
* def currentPage = '#(page)'

But the output was

#getToken

#page

What would be the best way? to these values for further utilization.

Upvotes: 1

Views: 2437

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Try this:

* def token = getToken
* def currentPage = page

Here's another thing, any variable defined in the calling feature will be visible, e.g. token so most of the time you don't need to pass arguments:

* print token
* print totalPages

Please avoid JS for loops as far as possible: https://github.com/intuit/karate#loops - and actually you seem to have missed the data-driven testing approach that Karate recommends: https://github.com/intuit/karate#the-karate-way

If you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Upvotes: 2

Related Questions