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

拟墨画扇 提交于 2020-05-16 02:22:43

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/61587366/karate-how-can-we-retrieve-the-value-from-called-feature-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!