如何匹配字符串并忽略空手道中的大小写?

How to match string and ignore the case in karate?

有一个值有时是小写有时是大写的情况。这是来自 API 的响应,我们必须通过忽略某些值来匹配响应中的每个字段是否正确。响应中的错误文本有时有一个小写的关键字,有些情况下是大写的。我们如何忽略字符串中的一个关键字以不匹配?我不想忽略整个文本,因为如果我忽略整个字符串,它可以正常工作,但是否可以只忽略一个关键字?

  Scenario: string matching
    * def test =
    """

    {
  "sourceType": "Error",
  "id": "123456",
  "type": "searchuser",
  "total": 0,
  "value": [
    {
      "details": "this is the user search case",
      "source": {
        "sourceType": "Error",
        "id": "77200203043",
        "issue": [
          {
            "severity": "high",
            "code": "678",
            "message": {
              "text": "No matching User details found"
            },
            "errorCode": "ERROR401"
          }
        ]
      },
      "user": {
        "status": "active"
      }
    }
  ]
}
    """
    * match test ==
    """
    {
  "sourceType": "Error",
  "id": "#present",
  "type": "searchuser",
  "total": 0,
  "value": [
    {
      "details": "#present",
      "source": {
        "sourceType": "Error",
        "id": "#ignore",
        "issue": [
          {
            "severity": "high",
            "code": "678",
            "message": {
              "text": "No matching User details found"
            },
            "errorCode": "ERROR401"
          }
        ]
      },
      "user": {
        "status": "active"
      }
    }
  ]
}
    """

这里如何只为用户忽略大小写?我在下面尝试过,但它将#ignore 视为一个值。

 "text": "No matching #ignore details found"

我不是在查看您的负载转储,而是提供了一个简单的示例。使用 karate.lowerCase():

* def response = { foo: 'Bar' }
* match karate.lowerCase(response) == { foo: 'bar' }

编辑:您也可以一次提取一个值并仅对其进行检查:

* def response = { foo: 'Bar' }
* def foo = response.foo
* match karate.lowerCase(foo) == 'bar'