0

下面是我的 json 文件:

[
  {
    "line": 1,
    "elements": [
      {
        "before": [
          {
            "result": {
              "duration": 1363286,
              "status": "passed"
            },
            "match": {
              "location": "Hooks.init(Scenario)"
            }
          }
        ],
        "line": 4,
        "name": "List Size test",
        "description": "",
        "id": "test-list-size;list-size-test",
        "after": [
          {
            "result": {
              "duration": 82262,
              "status": "passed"
            },
            "match": {
              "location": "Hooks.closeAllwindows()"
            }
          },
          {
            "result": {
              "duration": 127317,
              "status": "passed"
            },
            "match": {
              "location": "Hooks.embedScreenShot(Scenario)"
            }
          }
        ],
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 4170752,
              "status": "passed"
            },
            "line": 6,
            "name": "def test\u003d\u0027{     \\\"mytest\\\":[        {           \\\"test1\\\":\\\"abc\\\",         \\\"test2\\\":\\\"bcj\\\"      },      {           \\\"test1\\\":\\\"abc\\\",         \\\"test2\\\":\\\"bcj\\\"      }   ]}\u0027",
            "match": {
              "arguments": [
                {
                  "val": "test\u003d\u0027{     \\\"mytest\\\":[        {           \\\"test1\\\":\\\"abc\\\",         \\\"test2\\\":\\\"bcj\\\"      },      {           \\\"test1\\\":\\\"abc\\\",         \\\"test2\\\":\\\"bcj\\\"      }   ]}\u0027",
                  "offset": 4
                }
              ],
              "location": "APIStepDefs.def(StringBuilder)"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 980309,
              "status": "passed"
            },
            "line": 7,
            "name": "I convert \"${test}\" to response",
            "match": {
              "arguments": [
                {
                  "val": "${test}",
                  "offset": 11
                }
              ],
              "location": "UtilsStepDefs.i_convert_to_htf_response(String)"
            },
            "keyword": "And "
          },
          {
            "result": {
              "error_message": "java.lang.AssertionError: JSON PATH mytest LISTSIZE validation is failed .  Actual ArrayList size is :: 2 Expected ArrayList size is :: 3\r\n\tat org.testng.Assert.fail(Assert.java:96)\r\n\tat com.ingenico.htf.generickeywords.assertions.JsonAssertions$13.performJSONAssertion(JsonAssertions.java:323)\r\n\tat com.ingenico.htf.generickeywords.client.apiclient.APIClient.assertJSONResponse(APIClient.java:335)\r\n\tat com.ingenico.htf.generickeywords.stepdefs.APIStepDefs.assert_JSON(APIStepDefs.java:127)\r\n\tat ✽.assert JSONPATH LISTSIZE(src/test/features/CheckListSize2.feature:8)\r\n",
              "duration": 1293311,
              "status": "failed"
            },
            "line": 8,
            "name": "assert JSONPATH LISTSIZE",
            "match": {
              "arguments": [
                {
                  "val": "LISTSIZE",
                  "offset": 16
                }
              ],
              "location": "APIStepDefs.assert_JSON(JsonAssertions,DataTable)"
            },
            "rows": [
              {
                "cells": [
                  "mytest",
                  "3"
                ]
              }
            ],
            "keyword": "Then "
          }
        ],
        "tags": [
          {
            "name": "@listsize"
          }
        ]
      }
    ],
    "name": "Test List size",
    "description": "",
    "id": "test-list-size",
    "keyword": "Feature",
    "uri": "src/test/features/CheckListSize2.feature",
    "tags": []
  }
]

我想要所有那些elements.id,其中elements[*].steps[*].result 是'失败'

我尝试使用以下查询,但没有返回任何结果。

$..elements[?(@.steps[*].result=="failed")].id

当前行为:Json 列表为空 []

预期行为:查询必须返回结果状态为“失败”的所有 element.id。

例如:id = 'test-list-size;list-size-test'

有人可以帮忙吗?

4

1 回答 1

0

您使用的是哪个 JSONPath 评估器?是否有最大步数?以下适用于jayway

$..elements[*][?(@.steps[0].result.status=='failed' || @.steps[1].result.status=='failed' || @.steps[2].result.status=='failed')].id

输出:

[
   "test-list-size;list-size-test"
]

但是对于无法消化不存在的步骤的评估者来说,这将失败[n]

于 2019-03-18T16:09:52.190 回答