javascript 函数的多个参数

multiple arguments on javascript function

嘿,所以我在单独的文件中有一个 javascript 函数。

function polling_orderitem_CNCL(source_id, condition) {
    var i = 0;
    while (i < 10) {
        var result = karate.call('./polling/get_order_item.feature', {SourceId : source_id});
        var sCode = result.response.data.attributes.statusCode;
        karate.log('poll response', greeting);
        if (greeting == condition) {
            karate.log('condition satisfied, exiting');
            return;
        }
        karate.log('sleeping');
        java.lang.Thread.sleep(1000);
        i++;
    }
}

我在我的功能文件中这样调用它

* def waitUntil_CNCL = read('./polling/polling_orderitem_CNCL.js')
* call waitUntil_CNCL(ciSourceId, 'CNCL')

虽然 运行 我收到以下错误

[ERROR] Scenario: Get order and orderitem and verifications  Time
elapsed: 0.003 s  <<< ERROR
java.lang.RuntimeException: javascript evaluation failed: 'CNCL')
Caused by: javax.script.ScriptException:
<eval>:1:6 Expected ; but found )
'CNCL')

请阅读文档。除了使用 call 你可以 "invoke" 函数就像 "normal" JS: https://github.com/intuit/karate#js-function-argument-rules-for-call

试试这个:

* eval waitUntil_CNCL(ciSourceId, 'CNCL')