【问题标题】:Karate framework - What is the correct way to use conditional logic "if-then-else" in scenario?空手道框架 - 在场景中使用条件逻辑“if-then-else”的正确方法是什么?
【发布时间】:2018-09-08 17:12:39
【问题描述】:

我尝试了几种方法来利用这两个链接中提到的 IF-Else 条件逻辑

1 How to check additional values with if condition (using karate framework)?

[2]https://github.com/intuit/karate#conditional-logic

在尝试了不同的组合之后,我仍然没有成功,而且我看不到其他方法可以让我的场景发挥作用。为了更好地了解和理解,我附上了截图。

如图所示, output2.c.data 和 z.d.data 都是空数组。使用这两个引用我定义了
*def output4 = (z.d.data == output2.c.data ? {pass:true} : {pass:false})

我期待我的输出 - output4- 是 {"pass":true}

出于未知原因,我的场景给我的结果与我的预期相反。

【问题讨论】:

    标签: json cucumber-jvm karate


    【解决方案1】:

    您不能在 JavaScript 中对两个数组进行等于操作,这就是为什么需要空手道的“深度等于”match

    * def foo = { data: [] } 
    * def bar = { data: [] }
    
    # wrong
    * def result = foo.data == bar.data ? { pass: true } : { pass: false }
    * match result == { pass: false }
    
    # right
    * def result = karate.match(foo.data, bar.data).pass ? { pass: true } : { pass: false }
    * match result == { pass: true }
    

    编辑 - 这是一个更详细的答案:https://stackoverflow.com/a/50350442/143475

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 2022-12-17
      • 2013-06-26
      • 2011-01-24
      • 2020-09-14
      • 1970-01-01
      相关资源
      最近更新 更多