Last active
June 20, 2021 19:03
-
-
Save dougtoppin/92ad406e84c972dca98b5a9cc9abf143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Postman is an exceptionally useful tool for testing ReST apis. | |
The following is an example of how to use the xml2Json method in a test if you are getting back xml and want to test elements in the response. The reason that I am posting this is that I could not get xml2Json to work until I discovered (using the new console in Version 4.7.2) that I needed the include the .$. in the object reference. | |
So that this is completely self contained all this is doing is setting an env var with an xml string, getting that | |
var, converting it to json and then evaluating the content. | |
postman.setEnvironmentVariable("testresponse", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><myResponse isError=\"false\"/>"); | |
var xmlresponse = postman.getEnvironmentVariable("testresponse"); | |
var jsonObject = xml2Json(xmlresponse); | |
tests["isError false"] = jsonObject.myResponse.$.isError === "false"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for posting this.
I have been trying all day to figure out why postman gives me an error on code that seems to work for everyone else.