如何为soap标头和正文创建xPath

时间:2019-07-08 11:16:28

标签: xpath wiremock

我正在尝试为肥皂请求创建一个存根,其标题和正文如下:肥皂请求

<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns3="http://example.com/ws/Namespaces/CustomerCareProductAndInsurance/Types/Public/CommonDataModel.xsd"
    xmlns:inq="http://example.wsproduct.com/ws/Namespaces/Container/Public/InquireProductDetailsRequest.xsd"
    xmlns="http://example.wsproduct.com/ws/Namespaces/Types/Public/MessageHeader.xsd">
    <soap:Header>
        <MessageHeader>
            <TrackingMessageHeader>
                <version>224</version>
            </TrackingMessageHeader>
        </MessageHeader>
    </soap:Header>
    <soap:Body>
        <inq:InquireProductDetailsRequest>
            <inq:ProductSelector>
                <inq:code>013881004138416</inq:code>
            </inq:ProductSelector>
        </inq:InquireProductDetailsRequest>
    </soap:Body>
</soap:Envelope>

以下是我使用xPath匹配器创建的存根,但是它不起作用,并且我每次遇到的内容都不匹配。

 {
    "request": {
        "method": "POST",
        "url": "/inquireProductDetails",
        "headers": {
            "Content-Type": {
                "contains": "text/xml"
            }
        },
        "bodyPatterns": [
            {
                "matchesXPath": "//version='224'"
            },{
                "matchesXPath": "//code='013881004138416'"
            }
        ]
    },
    "response": {
        "transformers": [
            "response-template"
        ],
        "bodyFileName": "productDetails-Success-Response.xml",
        "status": 200
    }
}

有人可以帮助为上述肥皂请求创建匹配的xPath。在此先感谢!

1 个答案:

答案 0 :(得分:2)

尝试一下

{
    "request": {
        "method": "POST",
        "url": "/inquireProductDetails",
        "headers": {
            "Content-Type": {
                "contains": "text/xml"
            }
        },
       "bodyPatterns": [
            {
                "matchesXPath": "//*[local-name()='code'][text()='224']"
            },{
                "matchesXPath": "//*[local-name()='version'][text()='013881004138416']"
            }
        ]
    },
    "response": {
        "transformers": [
            "response-template"
        ],
        "bodyFileName": "productDetails-Success-Response.xml",
        "status": 200
    }
}