The need for reliable and reliable web services is growing as more businesses use the internet. How can you ensure your web service meets all requirements? Web Service Testing is essential.
This guide will help you test web services whether you are a new developer or a seasoned tester. Let’s get started!
What is a web service?
Web services can be defined in many different ways.
Web services are client/server applications or components . You can think of web services as communication methods between two devices via the network. You can choose between SOAP or REST web services. (You’ll find out more about them later).
How do you test them?
Web services testing can be tedious, but it is well worth the effort to keep your site running smoothly.
How to test a web service
I am often asked how to test web services. And the answer may surprise you: the same way as you would test any other app!
You may be surprised by the answer I give – it’s exactly like you would test any other app!
The best approach for normal functional testing web services is generally the same. Web services, however, are not like other applications. They don’t offer a GUI user interface.
You can take comfort knowing that the functional test techniques you’ve always used still work. Consider a web service as an internal business process, and then write your test cases accordingly.
Before automating a web service, ask these questions
Performance testing and other negative testing are more important because web services can be used for multiple purposes by different clients. It is important to ensure that these areas are covered by test coverage.
When automating a website service, a good question is:
- Is the service responding with the right values?
- What speed does the service respond to users?
- Is the service capable of handling unexpected and expected user loads?
- Is the service able to handle invalid values or exceptions due to bad data?
What is Web Service Testing Terminology?
Most testers face the biggest challenge of acclimating with web service terminology. Take, for example:
- WSDLs – An XML format that shows you how to access a website service. A WSDL is generated automatically for you. Many test tools can read a WSDL and provide all the information that you need to interact.
- SOAP – A protocol that uses XML format for information exchange to and from a Webservice.
- SOA – This is a way for companies to organize software that can quickly be modified to meet market needs.
- Web Services are units of software that run on a network. These services are usually designed to manage a particular business process. You can combine web services in many ways to achieve the desired functionality.
Once the terms above are clear, testing web services should be easy. It is also my opinion that breaking down something into easy-to-use examples is the best way to simplify it.
This series will focus on simple examples of how a web service works and what it is. Automation awesomeness is possible with knowledge and know-how.
What about Rest Services?
REST (Representational Status of Transfer) allows you to develop web services using the HTTP protocol. This makes it easier and has less overhead than web services that use SOAP.
The majority of people have switched from the older method of using a WSDL Web service to REST.
This post will focus on WSDL-based services and not REST. My post on Rest-Assured provides guidance on how to start testing REST APIs.
How to create a web service
Okay, let’s get started. Let’s make our own web service. The web service that we have created will be the foundation for the rest.
We will be able map the values back from the source when we begin testing the WSDL and services request.
Why should you create a web-based service?
If you are anything like me, the best way to learn is actually doing .
It helps to actually try something to get a better understanding of it. So I created a simple example of how I would create a web-service to teach the concepts of service testing.
Here’s how to create a web service
We will now create a simple web service that only uses one method and combines two numbers. It’s not the most exciting web service, but it will do the job.
- Make sure that you have these things ready before you begin.
- Microsoft’s Internet Information Services, (IIS), is available on your machine
Install the latest.Net Framework SDK
Make a directory called WebServices under your C:Inetpubwww.root (wwroot picture)
- Next, copy the following code to a notepad.
The first line basically states that it is a web-service and the language is C#.
- We then import System and System.Web.Services.
- Next, create our DEMOAddNumbers class and add our AddThis method. This accepts two integer parameters — x, and y. Then, we add them together and return an integer number mySum that includes the sum of all the parameters passed.
- The file should be saved as DEMOAddNumbers.asmx. FYI, asmx is the file extension for ASP.NET.
How to create a web.config file
This was necessary to make it work on my computer. I also needed to add a web.config to my directory. Copy the following code to a notepad:
Save the Web.config file to .
Verify that the Web Service works
Next, open your browser and type the following address into it:
The page should return 42. (Which, of course, is also the answer for the meaning of life. hehe). Sweet! Now we have a functioning web service! This web service will be used in Part 2 to answer the question “What is a WSDL?”
We now have a functioning web service! This web service will be used in Part 2 to answer the question: What is a WSDL?
It’s all about the WSDL
Now, let’s take a closer look at WSDL. A WSDL (XML document) is an XML document which describes the methods, parameters, namespace and URL of a web service. When a.asmx file is redirected to HTTP-GET , WSDLs and any other documentation forms are automatically enerated.
Take a look at:
You should see an HTML page explaining the DEMOAddNumbers Web Service and other information.
You can click on the AddThis link from this page to open another HTML page, which will allow you to test the operation of the service.
Pretty cool, huh?!? Let’s now take a closer look at the actual WSL.
Enter the following URL in your browser to access our web service:
You should see the WSDL for our web-service (DEMOAddNumbers). You will notice that the WSDL was generated automatically and not by us.
A WSDL document can be described as an XML document containing information about a Web service.
These are the four major sections of a WSDL .
- Element types These are data types used by web services.
You can see how the WSDL information matches the code of our web services.
- Message element This section describes the messages that are used by the web services and describes the data elements for an operation.
- Binding element This is a description of the communication protocols used in the web service.
- PortType element The fourth element, portType is considered the most important because it describes web services and all operations that can be done, as well the messages for the service.
In the section above, the portType element defines DEMOAddNumbersSoap, DEMOAddNumbersHttpGet, and DEMOAddNumbersSoapPost as the name of the ports, and “AddThis” as the name of the operation.
Notice also that the ports are a request-response operation. This means that our web service is able to receive a request and return a response. Here are some examples:
Submit a request for AddThisHttpGetIn
Returns a response called AddThisHtpGetIn
Let’s now look at how to send and receive a request using a web service.
Web Service Testing Responses and Requests
Let’s now look at the request and response of a web service.
Let’s first import our WSDL to our preferred test tool. I’m using SOAPUI (a free open-source tool), but you could use any tool.
Click on “FileNew soupUI Project” in SoapUI. Enter the Project Name in the New soapUI Project: AddNums. For Initial WSDL/WADL, enter:
SoapUI should import the “AddThis” method under projects AddNums\DEMOAddNumbersSOAP. The following will be displayed if you double-click on the AddThis “Request 1” link:
*Remember that the WSDL must contain all information required to interact with a Web service. SoapUi was able read the WSDL and generate a request for you with the right inputs.
Web Service Request/Response
Our DEMOAddNumbers web-service is the most common. A requester (in our case, our test instrument) sends a request and waits.
The service processes the request and then sends a response. Let’s take a look at this service in action.
Let’s send the valid service values to our request.
This is what I received back from SOAPUI when I sent my request:
What does SOAP have in common with Web Services?
What is the process of this communication? SOAP, which is an XML-based protocol that allows communication with a Web Service, sends information to the request via HTTP. SOAP stands to Simple Object Access Protocol. We will see soap elements like SOAP Header, SOAP Envelope and SOAP Body if we examine our request.
This is how a SOAP XML message looks like.
A Negative Test: If we send incorrect data, a SoapFault will occur. If we send. We should return a soapFault
We can see that the SOAP XML contains a Fault element. An Fault element can contain errors and status information.
Open Source API Testing Tools to Test REST- and WSDL Based Services
Selenium can only be used for browser-based testing. You might be wondering which tool you should use to test Rest and Soap web services-based.