【问题标题】:How can I iterate through normal array in karate?如何遍历空手道中的普通数组?
【发布时间】:2018-11-20 06:45:33
【问题描述】:

我的一项任务的输出是 ['a','b','c']

现在我必须在数据库查询中使用这些值

* def queryToGetHotelIdForAvailableCsId = "select id from hotels_hotel where cs_id in ('a','b','c');"

如何在空手道中做到这一点?

【问题讨论】:

    标签: karate


    【解决方案1】:

    使用 Java 助手可能会更好,但你可以这样做:

    * def json = ['a', 'b', 'c']
    * def fun = 
    """
    function(array) {
      var temp = '';
      for (var i = 0; i < array.length; i++) {
        if (i > 0) temp = temp + ',';
        temp = temp + "'" + array[i] + "'"
      }
      return '(' + temp + ')';
    }
    """
    * def result = fun(json)
    * match result == "('a','b','c')"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多