首页 > 解决方案 > 条件逻辑中驱动的数据未按预期工作

问题描述

我想在条件逻辑中对另一个功能文件进行数据驱动测试(普通编程语言有 if - else if - else if - else,但可能不支持空手道超过两个条件)。

这是我的演示功能文件:

Feature: conditional logic call demo

  Scenario:

    * def switchVar1 = 1
    * def switchVar2 = 2

    * table testVars
    |switchVar1|switchVar2|
    |'theOne1'  | 'theTwo1' |
    |'theOne2'  | 'theTwo2' |


# here I can not do data-driven test the feature file: 'callUsage/module1/demo_module1.feature' 
 * eval if(switchVar1 == 1) 
     karate.call('classpath:callUsage/module1/demo_module1.feature') testVars

错误日志

flow.feature:30 - javascript evaluation failed: if(switchVar1 == 1) karate.call('classpath:callUsage/module1/demo_module1.feature') testVars, <eval>:1:84 Expected ; but found testVars
if(switchVar1 == 1) karate.call('classpath:callUsage/module1/demo_module1.feature') testVars
                                                                                    ^ in <eval> at line number 1 at column number 84

标签: karate

解决方案


将值传递给karate.call不同于callaskarate.call应该像函数一样调用

尝试,

* eval if(switchVar1 == 1) karate.call('<FILE_PATH>', testVars) 

https://github.com/intuit/karate#karate-call


推荐阅读