'Body Expectation with XPATH not working on mockserver
I am using MockServer since a short time and trying to create an expectation on the Request-Body. My Body is an XML and I am using XPath to match the Request, but I can not make it work. The Expectation I defined:
[
{
"httpRequest": {
"method": "POST",
"headers": { "Content-Type": [ ".*/xml" ] },
"path": "/apath",
"body":{
"type" : "XPATH",
"xpath" : "bookstore"
}
},
"httpResponse": {
"statusCode": 200,
"headers": [
{ "name": "Content-Type", "values": [ "text/xml" ] }
],
"body": {
"type": "XML",
"xml": "<RS state=\"HAPPY DAYS!\"/>"
}
}
}
]
I tried several combinations I have been sending the simple XML from www.w3schools.com
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML</title><price>39.95</price>
</book>
</bookstore>
I tried matching on "xpath" : "bookstore", on "xpath" : "/bookstore" and as in https://www.mock-server.com/mock_server/creating_expectations.html#button_match_request_by_binary_body
"xpath" : "/bookstore/book[price>30]/price"
I always get the error "XPATH did not match".
Can anyone help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
