Automating SOAP API tests with SOAPUI

SOAP UI is a powerful and easy to use open source tool for automating different types of web services like SOAP, REST etc. It provides a UI for creating test cases,assertions making it easier to develop test cases rapidly.

SOAP UI caters to the needs of functional, regression, load testing and provides  features like

This blog covers basic steps and information on how to start off with SOAP UI, create basic test cases and assertions and execute the test cases.

Install SOAP UI

Install the latest free version of SOAP UI from http://www.soapui.org/

Create a project

  1. Open SOAP UI.
  2. Click on file->new SOAP UI project
  3. Provide the URL to the WSDL in the project creation window and click OK. A service binding for the WSDL will be generated with all operations.

When the WSDL for a services changes, it can be updated without affecting the test cases by right clicking on the service binding and choosing update definition.

Generating test suite/test case

  1. Right click on the service binding and select “Generate TestSuite”. Select the operations for which sample test case template has to be generated. A test suite will be generated for the selected operations.
  2. Right click on the test suite to generate a new test case

Adding steps in a test case

When a new test case is added, right click on the test case and select add step -> test request.Select the operation for which the request needs to be sent.

Once test case is added, different steps to the test case can be added.These steps form the blocks of the test case which are executed in order.

How to pass parameters to tags

Values for the tags in the SOAP request can be hard coded or parametrized. There  are two ways of doing passing parameters/values

Creating properties to transfer values: Properties can be used to store data. These can act as variables which can be passed to the SOAP requests.

Properties at a project : Properties can be defined at project and these are available for all the test suites and all test cases. Double click on project and click on properties tab at the bottom to create properties

Properties at the test suite level : Properties which are defined at the test suite level are available for all the test cases and test steps inside the suite. Double click on test suite and click on properties tab at the bottom to create properties

Properties at the test case : Properties at the test case are available for only that test case and all the test steps inside the test case. Right click on test case and select add step -> properties to create properties for a test case.

Declaring properties using properties test step

Declaring properties

Transferring properties using properties transfer test step

Transferring properties

Data driven by external files: Is available only in the commercial version

Creating assertions

Assertions are at the heart of any test case where the actual testing happens

SOAP UI provides different types of assertions. Double click on a test request inside a test case . You will find an assertions tab at the bottom and different kinds of assertions can be added.

Assertions

Running the test cases

Running from UI :

Double click on a project or test suite or test case and click on run button to execute tests at that level. Passed test steps in each of the test suite are shown in green and failed ones in red.

Running test cases from UI

Running from command prompt:

SOAP UI test cases can also be run from command prompt by using the following command

com.eviware.soapui.tools.SoapUITestCaseRunner (options)

Few options available

-s   Test suite to run

-c  Test case to run

-r  Turn on printing of summary report

Another easier way is to run the tests is using the testrunner batch file which comes along with the SOAP UI installation at /bin

testrunner.bat -sTemperatureServiceBindingTestSuite -j -f E:\SOAPUITestReport E:\SOAP-API-Automation-soapui-project.xml

-s is for the test suite

-j indicates that junit style HTML report will be generated

-f is for speficying the folder for report generation

Mentioning the location of project XML is mandatory

Running from ANT:

An ANT tagert can be created which executes this command line task to integrate with the builds.


<target name=”runSOAPUISuite”>
<exec executable=”C:\Program Files\eviware\soapUI-3.5\bin\testrunner.bat”>
<arg line=’-sTemperatureServiceBindingTestSuite -j -f E:\SOAPUITestReport E:\SOAP-API-Automation-soapui-project.xml’/>
</exec>
</target>

Importing the test cases

The test suites and projects can be exported and imported to different machines and thus can be shared and executed by other team members very easily as it provides the same view on import.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Hi Prashanti,
Im looking for an open source tool thru which i can automate XML API call’s and verification of response and some database checking…. please let me know whether i can use this soapUI tool or if found any other tool.
Awaiting for your reply.
Please email me at mohankrishna_palakurti@yahoo.com

Thanks,
Mohan

To use SoapUI for testing is not the best idea.
It has support for test cases and test suites, but the setup is extremely time-consuming.
Also, when compared to a JUnit test, it takes about twice as long to setup a property-driven test in SoapUI as it does to write the same JUnit test, and the JUnit test will be testing the ws client code.
SoapUI has some serious usability issues. Try to create a test that uses 3 services, where the first service is a login that returns a session id to be used for the other 2 services. It takes about 2-3 hours to create that in SoapUI, and about 1 hour in JUnit including the time to generate the client code from the WSDL.

Setting up SOAP UI is not at all time consuming.
You need to simply install it, create a project and import relevant WSDLs and you are good to go.
To create a test case which needs 3 services and passing the common session ID, it did not take me more than 20 minutes including importing the WSDLs.
We just need to create a property(at test suite level) called sessionID which can be used by all test cases in the suite.
In each test case,a property transfer step is all that is needed to pass the sessionID to the SOAP request.

Hello Prashanti can you give me a simple example of webservice test that uses 3 service.
Thanks. Looking forward for your response.

Hi Prashanti,
An example will definitely give us a better understanding of your views about the creation of test suites with 3 services.

I need help to call web service method by using Groovy Script, I also want to populate web method’s arguments with incremented values (using for loop).

Expected code is written below:

`for( i = 0; i < 1000; i++)
{
var request = EndpointReference.MyTestcase.Request;
request.Start = i;
request.End = i+100;
i += 100;
EndpointReference.MyTestcase.SendRequest(request);
}`

Any help will be highly appreciated.

Hi My client has asked to do a load test of SOAP API and I have committed to do the task. I have worked in Load Runner to test the web application but when i clicked on the client project URL it had some links and on clicking i get the below page

Test

The test form is only available for requests from the local machine.
SOAP 1.1

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /NetBasisServices.asmx HTTP/1.1
Host: netidapi.networthservices.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: “http://www.networthservices.com/netbasis/Costbasis”

string
string

string
string
string
string
string
string
string

string
string
string
string
string
string
string

boolean
string
string
string
boolean
string
string

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

string
string
string
string
string

string
string

string

SOAP 1.2

The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

POST /NetBasisServices.asmx HTTP/1.1
Host: netidapi.networthservices.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

etc……

My Question is can i use Load runner to test this application or SOAP Load testing is different from what i think and moreover why these coding is seen in all the pages.

Please any one help me with your suggestions………. or mail your suggestions to kannansk_2000@yahoo.com

Can any one help me how to integrate the jenkins with SOAP UI Tool

When we are ruuning scripts if we get any failure reports that failure log should send to our mail id .

u can use all this tools
Junit
Ant
Groovy
Hudson
Any help will be highly appreciated

Please be in touch
balaram.ait@gmail.com

@balaram
As you can trigger the SoapUI using ant the its pretty easy to integrate with Hudson.
refer http://java.dzone.com/articles/functional-web-services-testin-1?page=0,1

Email part:
I am not much sure about hudson detecting the failures in the report and send mail but one solution could be write some code which parse the report look for any failures and send out a mail . Again this program can be triggered very easily with hudson using ant .

refer : a) http://stackoverflow.com/questions/6648244/how-to-integrate-soapui-with-jenkins-hudson

b) http://blog.infostretch.com/integration-of-soa-testing-tool-with-continuous-build-integration-tool

Hi Prashanti,
If i want to automate this test case, can you provide me the suggestion for automating this test case using SOAP UI,
i know about SOAP UI and i worked manualy on it and also i automate some test cases also.
Issue is that if i run this for first time then it runs and if now i run second, third… and so on then it fails.
mailId- sharma.vinod090@gmail.com

Hi Vinod,

I do not see the what test case you are talking about.

Hi Prasanti,
we have some requests to be executed from the soap client.Executing every request and checking is time consuming…i want to automate these testing execution..is it possible??? can u give me the steps to be followed

Hi Vijaya,

As mentioned in the blog post, it is possible to trigger the SOAPUI testsuite from ANT and other build tools.
You can trigger the the whole test suite from command prompt instead of running each script one by one.

Prashanti

Hi Prashanti,

I have done datadriven test with excel using groovy script in soapui. But how to validate all the values present in excel using assertions. Please provide the solution.

Hello Prashanti,

My question is a combination of asked by Mahmood above and Vijaya lakhsmi.
I have data in an external sheet which needs to be executed for each call.
For Example: There are Input fields in my API
NAME
ADDRESS
ID

So I need to pass Name first and validate it against address and ID.
Then I pass Address and validate it against Name and ID
And finally ID and validate it against Name and Address

How do I do it?

Description provided is very helpful. But please provide the Screenshots as well.

informative post…

Leave a comment

(required)

(required)