我有一个空手道功能文件,我们称之为A.feature,旨在供其他功能文件重复使用。通过使用共享作用域,A.feature可以使用调用特征文件中定义的一些变量,例如国家/地区。我希望这些参数是可选的,但在A.feature 中定义了一个默认值。为此,我使用了三元条件逻辑,例如:
* def myCountry = (country ? country : 'us')
Run Code Online (Sandbox Code Playgroud)
但是,当未定义国家/地区时,
参考错误:“国家”未定义
被抛出。
有没有人知道如何解决这个问题,或者是否有 Nashorn 或 Karate 错误?
如果您想要完整的堆栈跟踪,请告诉我。
这将起作用:
* def country = typeof country == 'undefined' ? 'us' : country
Run Code Online (Sandbox Code Playgroud)
编辑 - 空手道现在有一个方便的 API 来做到这一点:
* def country = karate.get('country', 'us')
Run Code Online (Sandbox Code Playgroud)