Soapui
Soapui
Soapui
2.
SOAP
SOAP is a standard protocol defined by the W3C Standard for sending and
receiving web service requests and responses.
SOAP uses the XML format to send and receive the request and hence the
data is platform independent data. SOAP messages are exchanged between the
provider applications and receiving application within the SOAP envelops.
As SOAP uses the simple http transport protocol, its messages are not got
blocked by the firewalls.
REST
REST means REpresentational State Transfer; it is an architecture that generally
runs over HTTP. The REST style emphasizes the interactions between clients and
services, which are enhanced by having a limited number of operations. REST is
an alternative to SOAP (Simple Object Access Protocol) and instead of using XML
for request REST uses simple URL in some cases. Unlike SOAP, RESTFUL
applications uses HTTP build in headers to carry meta-information.
There are various code that REST use to determine whether user has access to
API or not like code 200 or 201 indicates successful interaction with response
body while 400 indicates a bad request or the request URI does not match the
APIs in the system. All API request parameters and method parameters can be
sent via eitherPOST or GET variables.
Rest API supports both XML and JSON format. It is usually preferred for mobile
and web apps as it makes app work faster and smoother There is one more
thing one needs to learn
WSDL
WSDL (Web Services Description Language) is an XML based language which will
be used to describe the services offered by a web service.
WSDL describes all the operations offered by the particular web service in the
XML format. It also defines how the services can be called, i.e what input value
we have to provide and what will be the format of the response it is going to
generate for each kind of service.
2.
3.
4.
5.
web service provider application over the http and able to parse and validate
the response XML against the expected result. In our case, we will test the
WebService
1.
Using Java
2.
Using SoapUI
2.
Using the stub we will invoke the request method by passing all the
required information.
3.
Stub program will convert that request into XML request format and
sends it the service end point which will read the request and processes the
request and sends the response in XML format.
4.
The XML response will be converted into Java class by stub and returned
to the actual program.
Step d) Once the command is successfully run, you will see the folder with
required files.
Step e) Next we have to create the client program, through which we will send
the actual request using the generated stubs. Open the eclipse and create the
new Java project and select the folder which we have created above.
Step f) Add all the axis2 related jars to project build path, which will be there in
lib folder of the axis2 software folder
(for ex : C:\Axis\axis2-1.6.2\lib)
Step g) Create a new Java class (ex : Client.Java) and instantiate stub object.
Using the stub object we can call all the supported methods of the particular
WebService.
Client.Java Program
package org.apache.axis2.currencyconvertor;
import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRate;
import
org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRateResponse;
import
org.apache.axis2.currencyconvertor.CurrencyConvertorStub.Currency;
public
class Client{
public
static
void main(Java.lang.String
args[]){
try{
//Create the stub object by passing the service end point url
CurrencyConvertorStub stub = new CurrencyConvertorStub(
"http://www.webservicex.net/CurrencyConvertor.asmx");
//ConversionRate is the class which we have to use mention the from and to
currency
//ConversionRate object will be the parameter for the
conversionRate operation
ConversionRate conversionRate = new ConversionRate();
conversionRate.setFromCurrency(Currency.USD);
conversionRate.setToCurrency(Currency.INR);
//We can use the conversionRateResponse object to retrieve the response of the
ConversionRate Service
System.out.println("Conversion Rate from INR to USD : " +
conversionRateResponse.getConversionRateResult());
} catch(Exception e){
e.printStackTrace();
}
}
2.
3.
Click OK
1.
Expand the first request and double click on the 'Request1'. It will display
the SOAP request in the XML format.
2.
3.
4.
As you may conclude, usage of tools like SoapUI expedites your WebService
Testing Effort. Hence SoapUi will be focus of our learning in the succeeding
tutorials.
Summary
FAQ
What is Difference between WebService and WebAPI?
Web Service
Web API
No defined standard
Example: REST
Example: SOAP
Introduction to SOAPUI
What is SOAP UI?
SOAP-UI supports all the standard protocols and technologies to test all
kinds of API's.
Performs Fuzzing scan and Boundary scan to avoid erratic behavior of the
services.
3) Load Testing
Maven
HUDSON
HUDSON, a JAVA based Continous integration tool and integrates with tools
such as CVS, Subversion, Git, Perforce, Clearcase, and RTC. SOAPUI also
integrates with HUDSON, which helps us to spot bugs quickly for each and
every commit by the developers.
JUnit
JUnit is a unit testing framework built in Java, which can control the flow of
tests from SOAP-UI as well.
Apache - Ant
Apache Ant, a Java library which is a command-line tool that helps in building
software. Using SOAP-UI's Command line, we can execute tests within an ANT
Automated Build.
SOAP UI Vs Selenium:
Let's compare SoapUI with Selenium
SOAP UI
Selenium
SO
JDBC
HTTP
Automation
Functional Tests
Load Tests
Mock Services
Code Generation
Command Line
Maven
CI and Build Integration
General Features
Standalone Application
Groovy Code Templates
Multi Environment Support
Floating Licenses
SQL Injection
XPath Injection
XML Bomb
Fuzzing Scan
Cross Site Scripting
Configurable Scans
Reporting
Load Testing Features
Rapid Load Tests from Functional Tests
Configurable Load Strategies
Load Test Assertions
Real-Time Statistics
Performance Monitoring
Statistics Exporting
Setup/TearDown using Groovy Scripting
loadUI Integration
Reporting
Reports
JUnit Reports
Report Data Export
WSDL HTML Report
WSDL Coverage
TestSuite Coverage
TestCase Coverage
Assertion Coverage
Message Recording Coverage
Data Driven: PRO Version, helps us to work with an external data source
such as text files, XML, Groovy, Excel, file, and Databases. This helps us to
scale our tests with a range of inputs driven through the above-said sources.
Test Coverage: PRO Version allows testers to get a statistic report which
shows the functionalities that are well tested and also the areas that are NOT
thoroughly tested as well. The drill down reports even pinpoints exactly what
has NOT been tested and what has NOT been asserted.
Test Debugging: You can then run the test to that breakpoint and view
the current value of the SoapUI properties. The Test Debugging Interface
simplifies following Test Flow, Variables, Properties, Requests, Context, and
much more, making test creation and improvement more streamlined.
SQL Builder: For Non-Technical testers writing complex SQL Query can be
cumbersome. The SOAP UI PRO's SQL Builder can help them in creating SQL
Query using the SQL Builder's graphical interface. This feature helps us to
accelerate the implementation of data-driven testing.
We will be using the Open Source version of SoapUI for our training purpose.
FAQ
What is Difference between WebService and WebAPI?
Web Service
Web API
No defined standard
Example: SOAP
Example: REST
SoapUI can test both Web Service and Web API. As a tester, you can forgot
about these differences and focus your energies on creating an exhaustive
automation suite.
Part A: Downloading
Navigate to http://www.soapui.org/
Scroll down and choose the downloader based on your operating system.
In this tutorial, we will install SOAP UI on a 64 bit Microsoft Windows
operating system.
Part B: Installing
Step 1: After downloading, execute the file as 'Administrator' as shown below
.
Step 3: Accept the license agreement and click 'Next' to continue.
Step 6: The installation wizard asks the user to download and install 'Load UI'.
Since Load testing is not the context of the discussion, we can proceed without
selecting it.
Step 7: If 'Hermes JMS' is selected in step#5, then the license agreement for
'Hermes JMS' pops up. Accept the license agreement and click 'Next'.
Step 7: Choose the folder location for tutorials or else leave the default location
as is and click 'Next'.
Step 8: Choose the start menu folder location or else leave the default location
as is and click 'Next'.
Step 9: Enable the checkbox 'create a desktop icon' and click 'Next'.
Step 10: The Installation starts and upon completing the same, the wizard
shows the below status. Click 'Finish'.
1.
Menu Bar
2.
3.
4.
Workspace Properties
5.
Log area
NOTE: You might see an upgrade screen like below. You can just Ignore the
Update
Part C: Configuring
Let us first understand the project structure in SOAP UI.
For Each Test Suite, there can be several test cases attached to it.
For Each Test Case, there can be several test steps associated with it.
Below is the pictorial representation of a workspace structure in SOAP-UI.
Step 3: Now the user has to select the path where this workspace has to be
saved.
1.
2.
3.
Step 4: The workspace is created as shown below. We can also access the
workspace properties under 'Workspace Properties' Tab.
1.
2.
3.
'Import Project' allows user to import the entire project by locating the
corresponding XML.
4.
'Save All Projects' allows user to save all the opened projects in a single
click.
5.
'Close All Open Projects' closes all the projects opened in that workspace.
6.
7.
8.
9.
Now, let us understand the 'Preferences' from the file menu. Upon
Clicking 'Preferences' from 'File' Menu, the below dialog opens.
o
We will go through the most frequently used 'HTTP Settings' in
details.
1.
2.
3.
4.
5.
6.
7.
8.
1.
2.
3.
4.
5.
6.
1.
2.
Now, we will go through the most frequently used 'UI Settings' in details.
Closes all projects while launching SOAP UI for better startup-time and
consumes less memory.
Displays description whenever available.
3.
4.
5.
Displays and expands the log tabs upon starting SOAP UI.
6.
7.
Upon disabling tool tip, disables tool tip when user hovers mouse over
the options/buttons while navigation.
HELP:
1.
4.
Allows user to navigate to the home page of www.soapui.org
5.
Displays the build and version information of the SOAP UI.
The upcoming tutorials will not only make you understand how to create test
suite, test case, and test steps but also let you test SOAP requests and how to
validate them.
After setting up the workspace which we had performed in the last tutorial, we
have to create projects, test suites, test cases in order to test a given web
service. Let us understand the steps involved in doing the same.
Create a Project
Step 1: Now depending upon the project, we need to import SOAP/REST
protocol. We will create a new SOAP Project.
3.
Note:
Upon checking Create, a Test Suite for the imported WSDL' creates a test
suite within the project for the imported WSDL.
Upon Checking Relative Path' enables the user to save all the files
relative to the project file.
Step 3: Upon creating the SOAP project with the above-said WSDL, we will be
able to see that there are two operations that will be imported into the project.
Step 4)
1.
Expand the first request and double click on the 'Request1'. It will display
the SOAP request in the XML format.
2.
3.
4.
You may wonder why create Test Cases? When you can directly test WebService
here
Well, you can send a request for one operation. What about others? How many
combinations of FOREX conversion you can do using this operation. You
have to edit the request for each and every combination.
For example: If you want to convert from GPB to INR instead of USD to INR
You need to edit the operation again. So, one has to create a test suite/cases to
have all possible scenarios tested without having to directly edit the operation
itself.
Step 2: We need to enter the name of the test suite and press OK.
Step 3: The created test suite is displayed the navigator pane as shown below.
Step 4: The test Suite window opens in the Right Pane. As we have just created
there are NO test cases. Hence all options are disabled.
Step 2: Specify the name of the test case and click 'OK'.
Step 3: The created test case has zero steps as shown below.
Note: We can see that the test case is added with zero test steps for all kinds of
tests available. Upon adding the test steps the numbers in the bracket would
change automatically. The functional test step
should go into 'Test Steps' while a performance test step should go into 'Load
Test' and a security test step should go into 'security Tests'.
Step 4: We can insert a variety of test steps by performing a right click on test
steps and selecting an appropriate test step as shown below. So if you were to
test a REST WebService, you would select the REST Test Request.
Step 3: Upon clicking 'OK', a dialog pops up to select the operation to invoke. All
the operations are listed, and user can select the operation that they would like
to invoke.
There are two operations that will be listed. Both the Operations are the
same except the SOAP version used.
CurrencyConvertorSoap uses SOAP version 1.1 where as,
The Version does not matter for us in this context. Hence you can select
the one of your choice.
Step 4: While adding a test case, we can add standard assertions. Assertions
also called as checkpoints/validation points which we will be dealing in detail in
the next tutorial.
We can add following checkpoints/assertions while creating test case. Let us
create a test case with the default option which means creating test step
WITHOUT any of the below validation points
Step 5: Upon creating the test case, the request XML is shown below. The
structure of the XML is explained within the below snapshot.
Step 6: The test step count is now incremented to one as we have just added
one test step. Similarly upon adding load and security tests step, the
FromCurrency USD
ToCurrency INR
Next,
1.
We need to enter these inputs in place of the question mark which will be
sent as request XML.
2.
After inputting those values into the corresponding XML tags, click
'submit request' button to check the response.
Step 2: Upon submitting a request the web service request is processed by the
webserver and sends back a response as shown below.
By reading the response, we are able to conclude that 1 unit of USD = 63.525
units of INR.
The Request is posted to the webserver. Hence, the POST method of Http
is used.
2.
Step 2: Now click 'RAW' Tab in SOAP-UI Response Window to understand how
the response is sent via HTTP.
1.
After processing the request, the Http response code (200) is shown
which means it is a success. The webserver has processed it successfully.
2.
The SOAP response is sent back to the client as part of the body of the
HTTP message.
A Quick snapshot of the Http Response codes for easy understanding and
debugging. The below table will help you to trouble shoot based on the HTTP
code received from the webserver.
Http Code
Description
1xx:
2xx:
3xx:
Redirection - This means further action must be taken in order to complete the request.
4xx:
Client Error - This means the request contains bad syntax or cannot be fulfilled
5xx:
Step 3: Let us understand the other information that are displayed in the test
case window.
1.
2.
3.
4.
LOGS PANE:
Logs pane has the complete information regarding the transaction between the
client and the server. Users will be able to see the tabs of the Log pane as
shown below. We will discuss the most commonly used log panes when working
with SOAP-UI.
SoapUI Log Displays the response information from webserver. The same
information is stored in soapui.log file of the SOAP-UI installed folder under
'bin' directory.
Http Log Displays all the HTTP packet transfer. All the information in 'RAW' is
shown in HTTP log.
Error Log Error log displays all the errors that we have encountered during
the entire project session. The same information is available in 'soapuierrors.log' present in the 'bin' directory of the SOAP UI installed location.
Memory Log This tab monitors the memory consumption and displays it in
the form of the chart as shown below. It is really helpful when there is a
memory intensive operation is performed.
Now that we have created test suite, test case, test step and got a response,
next step is to validate the response. We will deal with types of assertions in the
next tutorial.
Types Of Assertion
There are various ways of asserting a response; however we will focus on the
commonly used Assertions types while validating a response. Below are the
ones that are available in Open Source version of SoapUI.
Apart from the ones that are listed above, PRO version also has an inbuilt JDBC
Assertion using which we can assert if the web service has updated the
database correctly.
In this tutorial we will study
Contains Assertion
Not contains Assertion
X Path Match Assertion.
X Query Match Assertion
Scripting Assertion
CONTAINS ASSERTION
Searches for the existence of the specified string. It also supports regular
expression.
We will continue with the same example from the previous tutorial.
Step 1: By Default there are no assertions.
Step 2: Now,
1.
2.
3.
Click 'Add'
Step 3: Let us validate if the string '63' exist in the response. Click 'OK'
Note : We can also ignore case and add regular expression.
Step 4: Upon adding it, immediately assertion is executed and shows if VALID or
INVALID.
Step 5: Now Let us say we change the content of 'Contains Assertion' to '64' and
see what happens.
Step 6: The Assertion is executed and the result is thrown to the user. Since we
don't have the string "64" within the response, the assertion has failed.
2.
3.
Click 'Add'
Step 2: Let us validate if the string 'FromCurrency' exist in the response. Enter
the string 'FromCurrency' and Click 'OK'
Step 4: Now let us change the contents of the 'Not Contains Assertion' and see
what happens. We will check for the non-existence of the string
"ConversionRateResponse".
2.
3.
Click 'Add'
After declaring the namespace we need to refer the XPath using the
created name space.
Step 3: Now we need to enter the XPath of the XML node that we need to
validate.
//ns1:ConversionRateResult Gives us the Value of the node enclosed
between <ConversionRateResult> & </ConversionRateResult> and ns1
corresponds to the declared namespace which is pointing
to'http://www.webserviceX.NET/'
After entering the XML, we need to click on 'Select from current' so that value
from the current response would be picked up for comparison going forward.
Step 4: So far,
1.
After declaring the namespaces, we have entered the XPath of XML node
that we need to Validate.
2.
We Need to click 'Select from Current' to make the current value as the
expected value.
3.
The current value is shown to the user which we can modify if required.
4.
Click 'Save'.
Step 2: Perform a Right click on the existing project and select 'Add WSDL'.
Leave other options as default and Click 'OK' Button.
Step 4: Now let us add a test case within the same test suite that we had
created for testing the currency converter.
Step 5: Enter the name of the test case and Click 'OK' Button
Step 7: Add a new test step of Type 'Soap Test Request' as shown below.
Step 8: Enter the name of the test step. Let us say Supplier_by_City which
would be more meaningful Click 'OK'.
Step 9: Select the Operation that we would like to validate. In this case it is
'MedicareSupplierSoap -> GetSupplierByCity'. Click 'OK'.
Step 10: Enter the Name of the test case and click 'OK'.
Step 11: The Request XML Outline would be displayed as shown below.
Step 12: Now let us find all supplier information for the 'New York' City.
To do so, add the following lines to your code.
<GetSupplierByCity xmlns="http://www.webservicex.net/">
<City>New York</City>
</GetSupplierByCity>
WSDL in the below URL - http://www.webservicex.net/medicareSupplier.asmx?
op=GetSupplierByCity
Step 13: Upon executing the test, we receive the below response
Step 14: Let us say we need to Validate all the Supplier Number. We can't use
XPath Assertion as we need to have hundreds of XPath Assertion. Hence the
usage of XQuery is inevitable in this case.
XQuery Assertion helps us to validate a group of XML response which are
repetitive in nature.
2.
3.
Click 'Add'.
2.
For retrieving all the Supplier Number, We need to write an XPath Query
and we will place it within < SupplierNumber> and </ SupplierNumber> Tags.
3.
Click 'Select from the Current' which will execute from the current
response.
4.
Upon Clicking 'Select from the Current', All the Supplier Number are
listed.
5.
Click 'Save'.
// Namespace declaration
declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
{
// Iterating through all the supplier number
for $x in
//ns1:GetSupplierByCityResponse/ns1:SupplierDataLists/ns1:SupplierDatas/ns1:SupplierData
Step 17: XQuery Assertion is executed and displays the final result in the
'Assertion' Panel as shown below. Now we have successfully added an Xquery
assertion using which we have validated all the supplier Number information.
The same would be compared against the actuals, every time the request is sent
to the webserver.
Note: The actual values won't be displayed. If all actual values are same as that
of the expected values, then it displays VALID else it will display 'Failed'.
Scripting Assertions
This Assertion technique is the most widely used one as it is extremely difficult
to manage and maintain hundreds of assertions.
SOAP UI uses either Groovy Scripting or JavaScript for scripting assertions. The
scripting technique is adopted for developing a framework for testing SOAP.
Scripting assertions are used under following circumstances.
Scripting assertions are used for creating user defined assertions that are
NOT predefined by SOAP UI.
For Demonstrating Script assertions, we will make use of Currency converter
WSDL, the test case 'INR_to_USD' that we had created earlier.
Step 1 : Steps to add groovy script is same as that of other assertions except
that the assertion is not a predefined one. Instead it is a user defined assertion
which offers greater flexibilities than the inbuilt ones.
Select the Test step against which the assertion has to be added.
2.
3.
Click 'Add'.
Step 2 : The Scripting Dialog opens where user will be able to write user defined
script to validate the response XML.
Step 3 : Now let us write a groovy script to validate the Conversion Rate. The
Script is attached below with the comments embedded. It is recommended to
have knowledge on Java Script or Groovy Script before attempting to write your
own script.
//Define Groovy Utils and holder for validating the XML reponse content
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
1.
2.
3.
Note: The final Information pop up will always display with the message 'Script
Assertion Passed' as long as the script is syntactically correct. It has got no
correlation with your assertion within the script.
Click OK
Step 4 : Now the assertion Tab displays all the assertions that we had added for
this test suite with the Status against each one of those.
Step 5 : Now
1.
2.
3.
When a Response is short such that it can be validated using one of those
inbuilt assertions.
We can also use Inbuilt Assertion if the response sent from the web
server is always static in nature. If it is dynamic, we will not be able to assert
it using inbuilt assertions.
When usage of inbuilt assertions such as Time out assertions and security
assertions becomes inevitable.
Inbuilt Assertions holds good pretty well for one time usage where tests
need not be repeated.
Assertions Options:
The created assertions can be best controlled with the help of control
panel that is highlighted below.
Option
Description
Below are the features available exclusively in PRO Version of SOAP UI.
PRO version also helps us to Group assertions so that we can add one more
layer of validation to the created assertions.
AND: All assertions are evaluated as VALID assertion which will result in
PASSED group condition.OR: At least one of the assertions within the group
must be VALID in order to assert a group PASSED condition.
Pro Version also allows Cloning of Assertions: This option lets testers
to allow copying an assertion to a different test step in the same or a
different project.
Description
Contains
Searches for the existence of the specified string. It also supports regular expression.
Not Contains
Searches for the Non-existence of the specified string. It also supports regular expres
XPath Match
Uses XPath expression to select the target node and its values.
XQuery Match
Validates the HTML Document after downloading and it holds good to any property
HTML.
Verifies if the HTML response contains a status code that is not in the list of defined
Verifies if the last received message is not a SOAP Fault. It is very obvious that it is a
SOAP Test Steps.
Schema Compliance
Verifies if the last received message is compliant with the WSDL or WADL standard
definition. Holds good for SOAP and REST Test Steps.
SOAP Fault
Verifies if the last received message is a SOAP Fault. It is the inverse of 'NOT SOAP
SOAP Response
Verifies if the last received response is a valid SOAP Response and holds good for SO
Steps only.
Verifies if the HTML response contains a status code that is in the list of defined code
of 'Invalid HTTP Status Codes' Assertion.
WS-Addressing
Request
WS-Addressing
Response
WS-Security Status
Validates if the last received message contains valid WS-Security headers and holds g
SOAP Requests.
Script
Script Assertion
SLA
Response SLA
Validates if the response time of the last received response was within the defined lim
JMS
JMS Status
Verifies if the JMS request of the Test Step has executed successfully and holds good
with a JMS endpoint.
JMS Timeout
Verifies if that the JMS response of a test step did not took longer than the specified d
Security
Sensitive Information
Exposure
Verifies if the response message does not expose sensitive information about the targ
use this assertion for REST, SOAP and HTTP Test Steps.
Use the correct namespace. The Name space should be the URL where
the web service is located.
If you haven't got the desired output, verify if a valid input is passed in
the request.
For example, in currency converter, if you input the 'From currency' as 'XXX'
which is not existing, the output throws a fault code as 'SOAP-Client' which
means that the issue is with the parameter that is being passed from the
client side.
Ensure that you use the correct syntax while using XPATH and XQuery
assertion. You should NOT use dot instead of colon while using the above
assertion. The Syntax is //namespace:Tagname and NOT
//namespace.tagname. By doing so, you might end up having a message that
'NO match in current response' even though the tag name is correct.