Postman has become a popular ad hoc tool for use when developing new web services. However, it is often overlooked that Postman can also be used to perform and automate testing of web services. The following tutorial will detail using Postman to develop a test of a XML web service. The purpose of the web service is to convert temperatures and it will demonstrate how Postman can be configured to test the accuracy of the response returned by the web service.
If you don’t already have a copy of Postman, please visit this page: https://www.getpostman.com/apps
(Note that installing the App for Windows, Mac, or Linux is preferred over installing Postman for Chrome.)
After starting Postman, simply click on a new tab (one with a + sign) and then begin by selecting POST from the dropdown. Next, just to the right of POST, add the URL for the web service, in this case:
Next, click on the Headers tab so that you can input the two required HTTP headers into your request configuration:
SOAPAction: "https://www.w3schools.com/xml/FahrenheitToCelsius" Content-Type: text/xml
Now click on the Body tab, and paste the following XML request:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <FahrenheitToCelsius xmlns="https://www.w3schools.com/xml/"> <Fahrenheit>100</Fahrenheit> </FahrenheitToCelsius> </soap:Body> </soap:Envelope>
Now click on the Tests tab so that we can define the code that Postman will use to automatically check the response for accuracy. This is a bit more complicated for a XML-based service than for a JSON-based service because Postman only supports the use of JSON syntax when running its testing code. So the first line of code we need is for converting the XML to JSON format, which will then allow us to code the remainder of the test using JSON type syntax. (We’re hopeful that in the future the authors of Postman will enhance the testing function to allow the use of XPath statements for direct testing of XML responses without requiring conversion of XML to JSON.)
Next, you will notice a commented line of code (line 2) that when not commented, is helpful for viewing the generated JSON code. When you’re developing your own tests in the future you will likely want to use this code so that you can decipher the exact syntax needed for the test. Simply click on View and then Show Postman Console and you will notice that a separate window will open. This window will show the detail of each transaction you run and will also show the output of any console.log requests.
The last line of code is the result of deciphering the generated JSON from the console window and then converting that JSON to the equivalent syntax needed to test the value returned in FahrenheitToCelsiusResult.
var jsonObject = xml2Json(responseBody); //console.log(jsonObject); tests["Check Expected Celsius Value"] = jsonObject['soap:Envelope']['soap:Body'].FahrenheitToCelsiusResponse.FahrenheitToCelsiusResult === "37.7777777777778";
Now we are ready to send the configured request to the remote URL by clicking Send. The resulting response in the Body tab of the response should display the XML returned by the remote server, and within that content you should see the value 37.7777777777778 which is highlighted in the below screenshot. You should also notice that Postman displays the text (1/1) in green as part of the Tests tab. This gives us some immediate feedback that the test code successfully verified that the response contained the data we had configured for testing.
We can get further confirmation of the test result by clicking on the Tests tab and noting the additional green “Pass” indicator and text that tells us our test is successful. In the case of more complicated web services, you could add as many tests as needed, and still be able to easily and visually determine whether all passed or quickly locate those in red that may have failed.
Once you have your test configured and working correctly, you will want to click Save so that you can easily re-run this test in the future.
If this web service seems vaguely familiar to you, it’s because this particular web service corresponds with the CELSIUS example program located on this page from the RPG-XML Suite documentation site:
If you have RPG-XML Suite installed, you can also locate the example RPG code in the RXS/QRPGLESRC source file.
Of course, if you use RPG-XML Suite to offer your own web services, Postman is a great tool for testing your RPG-XML Suite programs being served by Apache during the development process. It can also be a valuable tool when testing any changes you make to your RPG programs over time. By creating a collection of Postman transactions while you are in development mode, you’ll be able to leverage those quickly after some time passes and your recall of all the details is not as recent