空手道框架 - 在场景中使用条件逻辑“if-then-else”的正确方法是什么?

问题描述 投票:1回答:1

我尝试了几种方法来使用这两个链接中提到的IF-Else条件逻辑 1 How to check additional values with if condition (using karate framework)? [2] https://github.com/intuit/karate#conditional-logic 尝试不同的组合后,我仍然不成功,我没有看到其他方法使我的方案工作。为了更好的可见性和理解,我附上了截图。 conditional logic issue in karate

如图所示,output2.c.data和z.d.data都是空数组。使用我已定义的这两个引用 *def output4 = (z.d.data == output2.c.data ? {pass:true} : {pass:false}) 我期待我的输出 - 输出4-是{"pass":true} 由于未知原因,我的情景给了我与我期望的相反的情况。

json cucumber-jvm karate
1个回答
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 }
© www.soinside.com 2019 - 2024. All rights reserved.