Web Services are server and client applications to interact with rest of the world over HTTP, or sometimes over SMTP. It is written for accepting requests and giving appropriate answers for each requests. It is assumed that it returns the same response if there is no changing in the request and the condition. Therefore testing and automating Web Services are very easy. You just need to know sending and receiving data and condition, then the rest of the jobs is playing with data and assertions. Information about the Web Services should be present in Web Services documentations and it should be understandable to the people from third party system.
Web applications take to the next step with the Web Services because you can open your system to rest of world without requiring language specific restrictions. This makes integrity of applications very easy. To be able to integrate two or more system, you just know that you are sending some data and receiving data.
I had a task for testing Web Services which was written as SOAP. In this post I want to explain my approach for automating test cases against to Web Services. Example is applied to SOAP services but you can also apply the framework for REST APIs.
What is SOAP
SOAP stands for Simple Object Access Protocol. It is a standard web services access protocol which was developed by Microsoft in 1998. It was developed for replacing older technologies Distributed Component Object Model (DCOM) and Common Object Request Broker Architecture (CORBA). SOAP uses XML (stands for Extensible Markup Language) format for sending and receiving requests. This makes the using SOAP complicated since you need to build requests manually for some languages. SOAP has a good supports for Java and .NET but it is problematic for Python and PHP, for more information click here.SOAP message is a standard XML but it has also the following elements:
- SOAP ENVELOP: Root element of SOAP messages, everything goes inside of the Envelop. It has two parts: Header and Body.
- SOAP HEADER: Header is an optional element. It is composed of any optional attributes which are needed to proceed requests.
- SOAP BODY: Body is mandatory element. It is composed of informations being sent and receiving informations from the requests.
- SOAP FAULT: Body is optional element. It contains fault information if there is any fault while processing the requests.
Testing SOAP SERVICES
Even SOAP is a old technology when we compare to REST model, it is still using most of the company especially .Net developer. The good part of SOAP, you can easily get good information about services with WSDL. You can use this link to check the methods and requested url. If you have search for testing SOAP services, most of the time you would have seen lots of links for using SOAPUI or some other tools like SOAPSonar, Web Services Studio, STORM, or add-on for browser as SOA Client. You can see a good list from this link. However there are lots of tools on the market, it is not that easy to test SOAP similar to developing for it. Most of the time 'tool is fool', you have to deal with it is learning curve and have to be contented with the features that tool can give you.
I used Python requests library to test the SOAP services. What I did is just creating a form variable within a triple-double quotes for Python docstring, like
"""this is triple-double quotes with V1: %s and V2: %s""" %(variable-1, variable-2)
At the end I am just calling requests.post method with sending url, headers, data,and other options. Check the following example: