[英]How to loop with in the feature file in karate
Hi i am trying to loop a List of Map in a feature file, below is my code嗨,我正在尝试在功能文件中循环地图列表,下面是我的代码
test.feature
Feature:
Background:
* def jsonPathTest = Java.type('com.test.utility.FileUtility').getNames()
Scenario:
* def jsonName = karate.get('jsonPathTest[' + __loop + ']')
Getting below error低于错误
java.lang.RuntimeException: javascript evaluation failed: karate.get('jsonPathTest[' + __loop + ']')
at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:115)
Caused by: javax.script.ScriptException: ReferenceError: "__loop" is not defined in <eval> at line number 1
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:454)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)
If i am calling another feature file with data its working:如果我使用数据调用另一个功能文件,则其工作:
test.feature
Feature:
Background:
* def jsonPathTest = Java.type('com.test.utility.FileUtility').getNames()
Scenario:
* call read('test2.feature') jsonPathTest
test2.feature
Feature:
Scenario:
* print __arg
But i want to loop with in the feature file only instead of calling another feature file and passing data.但我只想在功能文件中循环,而不是调用另一个功能文件并传递数据。 Please suggest me how can i do this.
请建议我如何做到这一点。 Thanks in advance.
提前致谢。
Personally I don't understand why you have this reluctance to use a second feature file to loop.我个人不明白为什么您不愿意使用第二个功能文件进行循环。 Actually it promotes re-use and Karate has good support for this.
实际上它促进了重复使用,空手道对此有很好的支持。
If you really insist, you have to use the Cucumber "native" way of looping which is called a Scenario Outline
.如果您真的坚持,则必须使用 Cucumber“本机”循环方式,称为
Scenario Outline
。 Here is the documentation: https://github.com/intuit/karate#the-cucumber-way这是文档: https : //github.com/intuit/karate#the-cucumber-way
Note that the disadvantage is that you can't have a dynamic number of rows.请注意,缺点是您不能拥有动态行数。 Which seems to be what you are trying to do.
这似乎是你想要做的。 If you have a dynamic number of rows and you want to use a single feature file, that is not supported in Karate.
如果您有动态数量的行并且您想使用单个特征文件,则空手道不支持该文件。
For a comparison between the two approaches in code, refer this example: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/search/dynamic-params.feature有关代码中两种方法之间的比较,请参阅此示例: https : //github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/search/dynamic-params.feature
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.