- Unit tests with JUnit / Cobertura and DOH / JSCoverage;
- Functional and Integration tests with Selenium 2.
There's one little caveat related to the conversion and the XPath assertions:
- When the server response contains a single JSON object, the conversion introduce a namespace into the generated XML.
- And this namespace depends on the server address.
JSON response produced by a REST service. |
Transformation into a XML payload with an inferred namespace. |
This automatic mapping to namespace server dependent does not allow to write server-agnostic code if you follow the suggested solution!
The following figures show a XPath match expression as documented in the SoapUI training materials. Sadly, running it against an XML with a namespace, this error is reported:
XPathContains assertion failed for path [//startDate/text()] : Exception missing content for xpath [//startDate/text()] in Response.
Simple XPath expression with the corresponding error message. |
Corrected XPath expression as suggested, now server dependent :( |
A simple solution consists in replacing the specified namespace with the meta-character '*', which match any namespace. As all elements of the XML document are under the scope of the inferred namespace, it's important to prefix all nodes of the XPath expression with '*:', as illustrated by the following figure.
Use of the '*' prefix to produce assertion server independent. |
A+, Dom
Awesome! I needed this for my SoapUI tests.
ReplyDeleteThanks
Andrew
You're welcome ;)
ReplyDeleteVery helpful, thanks!
ReplyDeleteHi
ReplyDeleteI have to send JSON request to my REST service. If i set parameter/Value pairs and set the accept and media type to be application/json and tried to invoke the resource, with failure message.Looks like the input request is not showing up in raw tab of the soap ui request.(not in json format either).How can i resolve this issues?
I guess you want to issue a GET request, right? Just once after having created a test step, with the header { 'Accept': 'application/json' } and some request parameters, the Raw view is effectively empty. If you've run it, you'll see it populated with on the first line:
Delete- the verb GET,
- your service URL,
- all parameters serialized in a form: ?name=value&name=value&...
- and the HTTP protocol version
Here is the Raw view content after a successful run:
GET http://127.0.0.1:8080/API/Nova/promotion?account=Costco&status=PENDING&toDate=2012-03-31 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Authorization: Basic ZXBvbGluc2tpQG5vdmEuY29tOk9uM09uMw==
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 127.0.0.1:8080
Cookie: $Version=0; JSESSIONID=B7DF915AE128E3E148EF20169027C5D9; $Path=/API/
I hope it helps.
A+, DOm
Thanks, this saved my day!
ReplyDeleteSuper.. Thanks Alot... :)
ReplyDeleteMy pleasure ;)
ReplyDeleteIt helped me a lot, thanks!
ReplyDeleteThank you, this saved my day too!
ReplyDeleteYou're welcome. I'm just sad to see that the issue has not been fixed :(
DeleteThank you so much for this post it helped me a lot
ReplyDelete