将 XML 字符串转换为 JSON 以在 Azure DevOps Rest API 中创建测试用例

问题描述 投票:0回答:0

我想使用 Rest Assured 来处理 Azure DevOps。在创建测试用例之前一切都很顺利。我能够使用硬编码字符串创建它。这不是很有用,因为我需要将字符串移植为 POJO 对象以实现可重用性。我在 Postman 上试过了,效果很好。首先,我尝试将 XML 字符串更改为 JSON,但总是出现未格式化 HTML 的错误。

这是Postman中的payload

{
        "op": "add",
        "path": "/fields/Microsoft.VSTS.TCM.Steps",
        "value": "<steps id=\"0\" last=\"1\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step></steps>"
    }

如何将其移植到 JSON?我的意思是 value 属性的值。

这是要在 Postman 中使用的 JSON 的移植版本。

[
    {
        "op": "add",
        "path": "/fields/System.Title",
        "from": null,
        "value": "new addition step apps new definition"
    },
    {
        "op": "add",
        "path": "/fields/Microsoft.VSTS.TCM.Steps",
        "value": {
            "id": "0",
            "last": "1",
            "steps": [
                {
                    "id": "2",
                    "type": "ValidateStep",
                    "parameterizedString": [
                        {
                            "isformatted": "true",
                            "value": "Input step 1"
                        },
                        {
                            "isformatted": "true",
                            "value": "Expectation step 1"
                        }
                    ],
                    "description": ""
                },
                {
                    "id": "2",
                    "type": "ValidateStep",
                    "parameterizedString": [
                        {
                            "isformatted": "true",
                            "value": "Input step 1"
                        },
                        {
                            "isformatted": "true",
                            "value": "Expectation step 1"
                        }
                    ],
                    "description": ""
                },
                {
                    "id": "2",
                    "type": "ValidateStep",
                    "parameterizedString": [
                        {
                            "isformatted": "true",
                            "value": "Input step 1"
                        },
                        {
                            "isformatted": "true",
                            "value": "Expectation step 1"
                        }
                    ],
                    "description": ""
                }
            ]
        }
    }
]

移植后的JSON在Postman中运行时,返回此错误。但是如果我使用上面的 String 格式,它就可以完美地工作。我需要将 value 参数的值移植到 JSON,以便我可以从它们创建 POJO 类。

json xml rest-assured azure-devops-rest-api postman-testcase
© www.soinside.com 2019 - 2024. All rights reserved.