【问题标题】:karate - how to match partial string of the field in response?空手道 - 如何匹配字段的部分字符串作为响应?
【发布时间】:2019-05-28 06:03:48
【问题描述】:

我有一个如下的 json 响应,我只想匹配字符串“harry”

在 autoComplete 中,id 在 autoCompleteAuthors 中

响应{“数据”:{ “自动完成”:[ 《哈利·霍尔》 ], “自动完成作者”:[ { "id": "search_authors_harry martinson", “标题”:“哈利·马丁森”, “类型”:“作者” } ] } }

请建议如何使用 contains 执行此验证?

我尝试了下面的方法,但它不起作用 * def autoComlete = 获取 response.data.autoComplete[*] * 匹配 autoComlete 包含任何 'harry'

【问题讨论】:

    标签: karate


    【解决方案1】:

    您可以在空手道中使用match each#regex 标记,

    区分大小写的匹配

    * match each $response.data.autoComplete == "#regex .*Harry.*"

    敏感匹配中的大小写

    * match each $response.data.autoComplete == "#regex (?i).*harry.*"

    希望这能满足您的需要。

    编辑: 根据 cmets 的要求传递名称

     * def query = 'harry'
     * match each $response.data.autoComplete == "#regex (?i).*" + query + ".*"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      • 2019-10-18
      • 1970-01-01
      • 2019-05-01
      相关资源
      最近更新 更多