空手道:我们如何从调用的特征文件中检索值 [英] Karate: How can we retrieve the value from called feature file
问题描述
我在功能文件A中有两个参数,并将这些值传递给另一个名为B的功能文件.
I have two parameter in feature file A and I pass those values to another feature file called B.
但是我无法在功能文件B中检索到预期的值
But I am unable to retrieve the values as expected in Feature file B
代码:
功能文件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
功能文件B:
* def token = '#(getToken)'
* def currentPage = '#(page)'
但是输出是
#getToken
#getToken
#page
什么是最好的方法?这些值以供进一步利用.
What would be the best way? to these values for further utilization.
推荐答案
尝试一下:
* def token = getToken
* def currentPage = page
这是另一回事,调用功能中定义的任何变量都是可见的,例如token
因此大多数时候您不需要传递参数:
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
请尽可能避免JS for循环: https://github.com/intuit/karate #loops -实际上,您似乎错过了Karate建议的数据驱动测试方法:
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
如果您仍然遇到问题,请执行以下过程: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
If you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
这篇关于空手道:我们如何从调用的特征文件中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!