In this second part you will discover how to prepare tests for SOAP Web Services using SoapUI. For a better understanding of this post you have to know the basics of SOAP WS. As stated in part 1 (http://googlielmo.blogspot.com/2013/12/soapui-part-1.html), I am always referring to the Open Source edition of SoapUI.
First of all let's have a quick look at the User Interface.
On the upper left part of the UI you can find the project navigator (1). It contains a tree structure of the projects in the workspace. Selecting an item in the navigator you can see its general properties on the bottom left part (2). The central area (3) is the main working area. At the bottom of it there's the logging area (4) containing different tabs, one for each log scope (general SoapUI, Jetty, http requests and responses, errors, memory consumption, etc.). SoapUi uses log4j (http://logging.apache.org/log4j/1.2/) for logging, so if you need to customize the log settings you can edit the $SOAPUI_HOME/bin/soapui-log4j.xml file and restart the tool.
Let's start creating our first project. In this post we are going to create a project and some tests for this (http://www.webservicex.net/globalweather.asmx) web service. Go to the project navigator and right click on the tree root (Projects). Select New SOAP Project. Choose a name for it (WheaterForecastTest, for example) and then set the Web Service WSDL (http://www.webservicex.net/globalweather.asmx?WSDL). Leave the Create Requests checkbox set as for default and click on the OK button. SoapUI, starting from the given WSDL, creates the project with two interfaces for the WS (see the figure below), one for the SOAP protocol release 1.1 and another for the SOAP protocol release 1.2:
You can delete the one for the release 1.1. We are going to use the one for the release 1.2 only. The GlobalWeather WS provides 2 methods:
Replace the ? placeholder in the template with a value, for example Ireland and execute the request clicking on the green arrow button on the upper left of the request window. SoapUI will execute the request and you should receive the following response:
You can see both request and response in raw format too:
Do the same for the other method of the WS.
Now that we checked the WS methods let's go to add a test suite. Right click on the WS interface name, choose Generate TestSuite and create it leaving the default values proposed by SoapUI:
A new TestSuite with two TestCases (one for each method of the WS under test) shoud be created by the tool:
Expand the GetCitiesByCountry TestCase and the relative Test Step and double click on it. The sample request created for it will be displayed in XML format. Repeat the same steps as for template requests for the WS (replace the ? placeholder with the Ireland value and run the request). Now you need to add some assertion to your test case to make it helpful. Click on the label Assertions at the bottom of the request editor. It will expand the asserions editor (it should be empty). Click on the + icon. You should see the Add Assertion dialog box:
Select Contains, then click on the Add button and add Dublin:
Click on the OK button and the TestCase will execute. If the response contains the Dublin value, then the assertion is verified and the Assertion and the TestCase will be marked in green. If not they will be both marked in red. The same way you could add more assertions for a single TestCase. You can decide to run a single TestCase only or the whole TestSuite.
These are the general steps for any SOAP Web Service you want to put under test through SoapUI.
First of all let's have a quick look at the User Interface.
On the upper left part of the UI you can find the project navigator (1). It contains a tree structure of the projects in the workspace. Selecting an item in the navigator you can see its general properties on the bottom left part (2). The central area (3) is the main working area. At the bottom of it there's the logging area (4) containing different tabs, one for each log scope (general SoapUI, Jetty, http requests and responses, errors, memory consumption, etc.). SoapUi uses log4j (http://logging.apache.org/log4j/1.2/) for logging, so if you need to customize the log settings you can edit the $SOAPUI_HOME/bin/soapui-log4j.xml file and restart the tool.
Let's start creating our first project. In this post we are going to create a project and some tests for this (http://www.webservicex.net/globalweather.asmx) web service. Go to the project navigator and right click on the tree root (Projects). Select New SOAP Project. Choose a name for it (WheaterForecastTest, for example) and then set the Web Service WSDL (http://www.webservicex.net/globalweather.asmx?WSDL). Leave the Create Requests checkbox set as for default and click on the OK button. SoapUI, starting from the given WSDL, creates the project with two interfaces for the WS (see the figure below), one for the SOAP protocol release 1.1 and another for the SOAP protocol release 1.2:
You can delete the one for the release 1.1. We are going to use the one for the release 1.2 only. The GlobalWeather WS provides 2 methods:
- GetCitiesByCountry: gets all the major cities covered by the WS by country name;
- GetWheater: gets the weather report for all the major cities for a given country.
Replace the ? placeholder in the template with a value, for example Ireland and execute the request clicking on the green arrow button on the upper left of the request window. SoapUI will execute the request and you should receive the following response:
You can see both request and response in raw format too:
Do the same for the other method of the WS.
Now that we checked the WS methods let's go to add a test suite. Right click on the WS interface name, choose Generate TestSuite and create it leaving the default values proposed by SoapUI:
A new TestSuite with two TestCases (one for each method of the WS under test) shoud be created by the tool:
Expand the GetCitiesByCountry TestCase and the relative Test Step and double click on it. The sample request created for it will be displayed in XML format. Repeat the same steps as for template requests for the WS (replace the ? placeholder with the Ireland value and run the request). Now you need to add some assertion to your test case to make it helpful. Click on the label Assertions at the bottom of the request editor. It will expand the asserions editor (it should be empty). Click on the + icon. You should see the Add Assertion dialog box:
Select Contains, then click on the Add button and add Dublin:
Click on the OK button and the TestCase will execute. If the response contains the Dublin value, then the assertion is verified and the Assertion and the TestCase will be marked in green. If not they will be both marked in red. The same way you could add more assertions for a single TestCase. You can decide to run a single TestCase only or the whole TestSuite.
These are the general steps for any SOAP Web Service you want to put under test through SoapUI.
Comments
Post a Comment