空手道中具有未定义变量的三元条件逻辑

Ternary conditional logic in Karate with undefined variable

我有一个空手道功能文件,我们称它为 A.feature,旨在供其他功能文件重复使用。通过使用共享范围,A.feature 可以使用调用功能文件中定义的一些变量,例如国家/地区。我希望这些参数是可选的,但具有在 A.feature 中定义的默认值。为此,我使用三元条件逻辑,例如:

* def myCountry = (country ? country : 'us')

然而,当 country 未定义时,

ReferenceError: "country" is not defined

被抛出。

有没有人知道如何解决这个问题,或者是否存在 Nashorn 或 Karate 错误?

如果你想要完整的堆栈跟踪,请告诉我。

这会起作用:

* def country = typeof country == 'undefined' ? 'us' : country

编辑 - 空手道现在可以方便地 API 执行此操作:

* def country = karate.get('country', 'us')

更简单的方法是使用 default values:

* def country = karate.get('country', 'us')