SoapUI API Automation.

Francis Manoj Fernando
4 min readMar 4, 2018

January was full with client requirements, project proposals, research and development. Well its business as usual for a software engineer.

During a weekend I was doing a research on API automation tools. I had previous experience using Apache Jmeter, that I used for load testing and auto scaling, so I chose to evaluate Postman and SoapUI instead. One of the main reasons to go ahead with them was to reduce the learning curve for existing manual testers. Simply I just wanted a UI based tool.

Most of the developers used Postman or similar tool just to check web service endpoints. After that dev’s totally forgets about it. Why not use them to create a regression test suite ? This is without adding a huge overhead on the development. Postman is easy and you can find many tutorials to learn how to achieve this. But SoapUI wasn't that easy in the beginning comparing with Postman, and this read is all about sharing my experience with it.

SOAP UI

Disclaimer :- I might not be using the best practices, so don’t expect me to be 100% correct this is how I made it work for my requirement.

First create a REST Project then add a new service from URI.

There can be one or more endpoint, stick to the REST convention and you will be fine. I have create a dummy Service URI called http://stage.server.com. Next what need to do is to add the REST Resources bound to the Service URI. When adding these resources make sure to parameterised them, this will make your life easy in the years to come, trust me :D

I have put variables for version, company and country.

After adding the resources URI you can add the methods (GET/POST/Ect.) templates related to the resource. URI parameters will come automatically when you do this. (I told you it will be useful :P).

I have put a template for the JSON payload and there is a variable inside the payload called customerOrderRef — ${#TestSuite#customerOrderRef}. customerOrderRef is in the TestSuite level scope. This request need a unique messageID in the header when making a call, to make it dynamic I have put another TestCase level scope variable to the messageID custom header ${#TestCase#messageID}. Additionally request need basic authentication.

This is not going to be the request but just only the template for it. Before making the call we need to generate the parameters and do the necessary changes.

After adding the methods available you can create Test Suite then add Test Case to it. I have added two Groovy Script steps and a REST Request step. Two Groovy scripts are for pre and post. Pre groovy script will prepare the parameters needed for the REST request and Post groovy script will be used to store payload data for future requests. When create a REST Request used the previously created template :)

After adding the steps you might see something like this.

When adding the REST Request fill the parameters to your need.

Adding a REST Request

If you look at the REST Request parameters we need to generate the customerOrderRef and messageID variables before the making the request. We can add them to pre groovy script.

https://pastebin.com/embed_iframe/F1r1Yyn6 <— (get the code from here)

Groovy is almost like Java and the syntax is similar. what needs to note in the script is how to set variables in different scopes.

Now the REST request is ready to send to the server and if things go according to the plan you will get a response. Verifying the response(Assertions) are the most important steps when creating a automation test. SOAPUI is rich with simple assertions from UI, but I will use script assertions because they have the maximum flexibility.

https://pastebin.com/embed_iframe/td9VuQX3

Things to note here is how to get the response string, how to parse it to JSON, accessing the JSON value, getting the test suite variable and finally how to assert.

Test Case is almost done, but need to save the generated orderID in test suite scope so it can be used todo additional test cases. I have used to set it in the post groovy step. It took a lot of time to figure the code out since there are very few help there to refer and the logic behind was bit complex.

https://pastebin.com/embed_iframe/QdQyH41r

Hard part here was the way to access the previous steps response.

Well thats pretty much it. Content here will not make sense if you haven’t try to do some automation with SOAPUI and struggle, if you do I hope some of these will help you out.

Thanks.

--

--