http://www.technicalpage.net/search/label/SQL

> SOAP UI - Web Services Testing

SOAP based Web Services (API):

SOAP is a protocol , Simple Object Access Protocol,  works upon  http(internet), uses XML only.
It has/uses:
End Point URL
Request in XML
Response in XML

Tool to test SOAP based API:
SOAP UI
It is a tool to test web services - API (SOAP or REST ).  Soap UI is available free (open source) version and paid version(professional version-Soap UI Pro). Soap UI is built on Java Platform. Soap UI GUI uses Swing library.

We will discuss about the open source version of Soap UI.
In Soap UI, you can create API Project, Import Project, create Request, create Test Suite , create Test case , create  Test steps.

SOAPUI user interface and components :
The User Interface has three sections, Project Editor , Request Editor and Response Editor.  When you run a request(code for request is in request editor section), you get response for that in response editor section.  The Projects, Requests , Test Case, Test Suites, Test Steps are  displayed in the Project Editor section. You can see the request and response in the formats : XML, Raw.
Image # 1 :

Whatever elements you select in the Project Editor, you get the corresponding Property and Value at the bottom of the Project Editor. Different logs are available in the SOAP UI GUI, they are : SoapUI log , http log , jetty log , error log , wsrm log , memory log. These logs will be helpful when you need to troubleshoot something.


To configure the different settings and preferences, you can use "Preferneces" tab.  image #3


What is wsdl ?
WebService Description Language - Description of the webservice: It is an XML document which contains the details about the web service( API request in the web service) in other word SOAP based API request. Using the wsdl you can create API requests. For practice purpose, you can search free wsdl online and practice with that. wsdl is an URL ending with "...?wsdl". You can check if the URL works or not by browsing that URL, if working, you get the XML when you browse it, that is why it is an XML document. In real projects, developers develop the wsdl and give to testers for testing purpose.

Create a SOAP project:
Click FILE -> Create new SOAP Project  or click SOAP icon
Enter the wsdl URL in the "Initial WSDL" field. As soon as you enter the WSDL, it automatically populates the Project Name but you can also give the project name you want just changing the Project Name.  Check the box for "Create Sample Requests for all Operations ?"
Click OK

If the WSDL is successful, you get the project, the interface and api calls( also called api requests or methods or functions) created in the Project Editor section under interface. Every method are having one request. The requests are having icon SOAP.  If there is duplicate API (or interface) also created with the API, you can delete(Remove) that.

Run/Test a request:
Double click a request to open a request(request is xml file). It opens the request code(request.xml) in the Request Editor , you provide the appropriate input or inputs in the fields marked as "?"("?" is your attribute), some requests do not have input fields(means no “?”) so they are to be run as it is.  Click the green triangular icon(submit request) to run the request. This means you send your request to certain server, the server address is populated at the title bar as soon as you click the request in the request editor(Image #1 ). When you click run/submit, If there is error, you get error or the request does not run properly. If everything is good, then the request is processed and you get the response(response.xml) in the Response Editor or response section. 

You can check/validate the request code(request.xml) ,  to make sure if the request code is correct, by right clicking in the request editor and clicking "Validate" (or ALT + V) . If you get "OK" , that means the request code is ok.

Security of the code/data in SOAP:
To provide security to the code, the xml used here is not normal xml, it uses soap based xml. There are three tags in the xml(request xml) : Soap Envelop, Soap Header and Soap Body. Response(xml) also  have  tags : Soap Envelop and Soap Body. 

Generate Test Suite , Test Cases, Test Steps:


You can create Test Suite two ways: 1. Right clicking the project and 2. Right clicking the interface.

1.           Right clicking the project creates blank Test suite. In side this test suite, you can create any number of test cases. And test steps inside test cases. While creating test steps, you get option to choose the methods which is the method is the xml request. While selecting the request, keep the check box checked for “Add SOAP Response Assertion:” It would be nice to create Test suite , Test case and Test steps this way without touching the Interface.

2. Right click the interface (marked by two green arrows left pointed and right pointed) -->  Click "Generate TestSuite" --> In Style , select "One TestCase for each operation" --> Select the checkboxes for the APIs(API Requests) those you want to put into the Test Suite  --> Click "OK" --> Give Test Suite name and click "OK".
Test Suite is created, you will see that one Test case is created for every API requests you selected(The API Request check boxes selected earlier).
( Above if you select the style "Single TestCase with one Request for each Operation" , then you will get just a single test case with all the API requests as test steps.)
Like the requests, we can run test step inside the test cases, entering the inputs at the fields marked by  "?" and clicking run icon(green triangular icon) in the Request Editor and get the response in the Response Editor.
Inside the Test Suite, you can add  test case and test steps.

Validate the Soap Response(Results):

This is adding validation in the soap requests or test cases. We add validation by adding assertions.

Validate the Soap Response(Results):
This is adding validation in the soap requests or test cases. We add validation by adding assertions.

Assertions: 
Assertions are different ways to validate the response. Most common assertions are "Contains", "Not Contains" and "Xpath Match". There are other assertions also . Here we will discuss about "Contains" and "Not Contains".

To add assertion, you need to open the test or request. In the request editor, header - left side , with the run icon , there is green plus(+) icon, you can click that plus icon. OR you can click "Assertions()" just below the request editor (below and left) and then click the green plus icon.

Assertion "Contains"
Let's discuss about assertion "Contains" : When you enter a string text in the "Contains" assertion(field), after you run , SOAPUI checks , if the entered text is present in the  response and if it finds that text, the assertion (test case or request) is passed. If the text or string is not found, then failed.

Assertion "Not Contains" :
This is opposite to "Contains". It checks for absence of the given string or text in the response.  Check the box for "Ignore case in comparision " if you want  SOAPUI to ignore the case while using "Contains" or "Not Contains" assertions.
If you add the same type of assertion  again(more than once) , it asks for an unique name of the assertion.
After you add assertion, the request or test case turns green when it passes . Requests or Testcase turns red if it fails.

Hierarchy
The hierarchy of SOAPUI Project is : Project --> Test Suite --> Test Case --> Test Step
A project can have n number of Test Suites, A Test suite can have n number of Test cases, A Test case can have n number of Test Steps.
When you run a test step, only that test step runs.
When you run a test case, all the test steps inside the test case run.
When you run a test suite, all the test cases inside the test suite run.

Run in Sequence or Parallel:
When you want to run a test suite, double click the test suite --> a pop up appears --> it has options for running in sequence or parallel as shown in below image 4 :
When you run in sequence, the test cases run in sequence one after another.
When you run in parallel, all test cases are triggered simultaneously and run in parallel.


When you run Test Suite, if any test case inside it fails, the test suite is considered as FAIL.
Similarly, if you run Test case, if any test step inside it fails, the test case is considered as FAIL.

Generate API documentation :
To generate API documentation in HTML, you have to right click the wsdl service, click "Generate Documentation" , mention the output folder location and click OK.
It generates HTML document with detail information about the API's present in the webservice.  You can click detail of each API , you can find out its description, input and output parameters. Documentation is useful if you have to send it to somebody with the webservice inforamtion, api and their detail .

SOAPUI Update Definition:
Right click the wsdl webservice, click Update Definition or (F5) . This will update the webservice, If there is any update in wsdl or API or anything in the backend.

Manage Properties in SOAP UI:


You can create properties in Project Level and Test Suite Level, test case level and test step level.
You can click the respective project or test suite or test case or test step , go to bottom of the window that appears, click Properties tab and click “+” icon, add Property Name(say EMPID) and Property Value(say 100). The properties you created will be custom properties.

To see the properties, click the respective project or test suite or test case or test step . You will see the properties just below the the project section. If you click the custom properties tab, you will see the custom properties ie , the properties you created for the project or test suite or test case or test step.
To access the properties :
${#Project#PropertyName} --> for Project level
${#TestSuite# PropertyName} --> for Test Suite level
${#TestCase#PropertyName} --> for Test Case level
${#TestStepName#PropertyName } --> for Test Step level
${#System#PropertyName } --> System Property
${#Env#PropertyName } --> Environmental Property
${#Global#PropertyName } --> for Global Property

Use this syntax or code replacing the “?” in request . In the property, you write the “PropertyName” in the "Name " column and the  respective value in the "Value" column. And request will run for the respective property value and show the response.
Such as , you replace "?" with ${#Project#EMPID} and run the request xml, and you get the response for the EMPID= 100.

Soap UI Groovy Script:
In Progress...

Soap UI Mock Service:
In Progress...






No comments:

Post a Comment