Monday, December 8, 2014

Working With Mock Services (Dynamic Mock Services) in SOAPUI



In my last post, we have seen that what is mock service and how to use it. In the previous blog (http://lgsofttest.blogspot.no/2014/07/web-service-testing-using-mock-service.html) I have described about static mock response, meaning only one response for different inputs in request. Now in this post I am going to describe about dynamic mock response, which gives different response for each different input in request.


Let us start, Create project and test suite, and add Request to Mock Service, as described in my previous blog (http://lgsofttest.blogspot.no/2014/07/web-service-testing-using-mock-service.html). The project structure looks like below, we can see here Default mock response also created.

















Before going to next step, we need to prepare the Input and output test data. We need input data to feed the request xml and same we need output data to configure the mock response. Below is sample test date I have prepared for this post and it look like below,







Now we need to write some groovy script to configure the Mock Response to do this, follow the steps.

Go to “GetGeoIP” request in Mock Service open it by right click or double click on it, Mock Service request editor opens, it will looks like below,




















Now in the above screen we can see Mock response, and Interface and Operation name. In addition, in below pane we can see Dispatch and value as “SEQUENCE”; this is use for passing value or configuring the mock response. Now to configure mock response as per our predefined response values we need to write groovy script, hence select Dispatch value as “SCRIPT”. Once you selected Dispatch as “SCRIPT” and Default Response will be “Response 1”, which is same as mock response, which created when we added our request to mock services. Below is screenshot how it looks like,



















As shown in above screenshot, in Script editor need to write groovy script to configure the mock response. Below is the code to configure the mock response xml.

Mock response has five fields looks like below,
Now write groovy script to pass value to these five fields in mock response.





















Now let us describe the groovy script, in simple steps I will try to explain the script.

Step 1 :- Import all necessary packages the groovy, groovy Utils and excel packages.
Step 2 :- Create objects groovyutil to read the response xml. Using requestxmlholder read all the tags in the response xml.
Step 3 :- Read the excel file from the path, and by using for loop condition we can iterate the excel file until its last row.
Step 4 :- Now assign each cell value to a variable.
Step 5 :- Set variable to response xml tag, the value is the variable will set the by this statement.

Once script is ready save the project, and now add above created variable to response xml tag as below,


In above screenshot we can see mapping of the variables to respective xml tags in mock response xml.

Now we are done with mock response xml configuration dynamically. The groovy script will assign new value every time when the mock response when called by the services. With this, we will get different value in response with this we can assume our service is working fine.
Now run the Test Suite to check request and response for different input to different output. Import the excel file which we have created above to Data Source, and map the fields to request xml.
Start the mock service on the host and port as configured (Refer my previous blog to configure the mock service with host and port name http://lgsofttest.blogspot.no/2014/07/web-service-testing-using-mock-service.html).
Running mock service will look like below,















Below screenshot shows, the request xml is running on the mock service (Mock Service Endpoint in address bar), and value configured from Data source for request xml field.




















Now open the Test Case and run the test case,

















Once the test case running completed verify the request and response xml, to validate the result.




















Click on any of the request to check input data in request xml and output data in response xml.

Request XML with Input data,
















Response xml from Mock response which configured by Groovy script,






















Finally, we are done with mock service testing for our request.

In my next post, I will describe another way of Dynamic mock service.



                             That’s all Folks.


Friday, July 25, 2014

Web Service Testing Using Mock Service in SoapUI.



In This post, I am going to describe you on the very most useful features of SOAPUI, i.e. “Mock Services”.  
First, we should know what “Mock Service” is.
Here Mocking means verifying or testing the actual functionality of a product before testing the product on real service.

In short, when we do not have access to the real web service or server, then simulating or creating stub or local service to check the actual functionality of the service is working fine.

To mock the service please follow the steps,

In this post, I will describe the different ways of testing the service using Mock Service features of SoapUI.
There are two types of Mock Services,
1.      Static Mock Response.
2.      Dynamic Mock Response.

In Static Mock Response, we will get only one kind of response,
In Dynamic Mock Response, Different Mock Response for each or different request receive. Just like live service.

Now let us start with creating Mock Service in SoapUI. Here for my post purpose I am using ‘geoipservice’ (http://www.webservicex.net/geoipservice.asmx?WSDL).

By using above WSDL, create Project as described in my previous post (http://lgsofttest.blogspot.no/2013/12/basics-of-webservice-testing-tool-soapui.html) once you create project, in SoapUI it looks likes as shown in below,

 Now expand the service ‘GetIPServiceSoap’, there you will find the Request or Operations, and create test suite and test case for the request “GetGeoIP”. Please refer my previous blog (http://lgsofttest.blogspot.no/2013/12/basics-of-webservice-testing-tool-soapui.html) to create the Test Suite, Test Case and how to add Test Steps.

In addition, add Data Source and Data Source Loop steps to the Test Step.
Once you done with creating Test Suite and Test Case along with Request in Test Step, the project structure looks like below.


Now it is time to add our request to Mock Service, select the request of the “GetGeoIP”, right click on it, and select ‘Add to MockService’, as below.





















When you select the ‘Add to MockService’ then you will one smaller window, which ask for the name that you want to give it to the mock service. Here I will rename the service as “Test Mock Service” and Click on ‘OK’ button, then SoapUI will add request to Mock Service with default Response attached to it, once you done with it and looks like below;

OR
In a case where we do not have, any default response then have to add our own response valid xml format.
For the post purpose, here I will use the default response.

Now most important thing to do is, creating Test data for our request, in our request there is only one field is present, where need to enter the IP address, along with this need to Response data to the same file (or you can use different file as per your requirements).

Here I will add Test data and response data into the same file and finally the excel file looks like below,

Import this excel file into the Data Source in the Test Step, Refer my previous blog (http://lgsofttest.blogspot.no/2013/04/datadriven-testing-from-soapui-using.html) for how to import excel file to Data Source and mapping the fields.

Once importing the excel file and mapping to fields is done then Data Source and our Request looks like below;

DataSource:-
Request:-
Now it is time to move on to the Mock Service section,

Open the Mock Service that we have created above with the name as ‘Test Mock Service’. Open it by double click or Right Click and select ‘Show MockService Editor’. Mock Service editor opens there you will see the Request Name as ‘GetGeoIP’; this is the request which we have added to Mock Service.
It is time to start the Mock Service, by clicking the ‘Start’ button, but before that, we need to configure the Mock Response. To do that Click on the Request, which is present under Mock Service editor, now you will see Response 1 in GetGeoIP request.


Option I :- Static Mock Response
Provide the values as per your requirement in the default response xml. Here I have provided or configured the Mock Response or Default Response xml with some sample values and it looks like below,

Now we all set to test our service/Request using Mock Service with Mock Response.

Click on Setting buttonto configure the Mock Service details, such as Port Number, Host Name and other stuffs as per your needs, please find the below screen shot which I have configured the mock service. Once configuration is done Click on OK.


Click thebutton to start the Mock Server/Service. The Mock Service will run on the Host and Port on which you provided in settings.
Once you start the mock service, you can see the service running status in Mock Service Editor bar as below,


Once you confirmed that the Mock Service is running, and then go to Test Suite where request is present open the request and add the new endpoint as same as which you configured in Mock Service settings box. This New endpoint you can get from browser address bar when you click the button in Mock Service editor (as shown in above screenshot.), follow the steps to add new endpoint or server address as below,


Once you select the Option as “add new endpoint” one-popup box opens, there need to enter the new endpoint and click ok, new endpoint will looks like below and its visible in address bar;


Make sure the Mock Service is running , and now Click thebutton to Run the request, once the request executed successfully in right hand side pane you will see the response which is same as you configured in Mock Services section.

Open the Test Case Editor to execute all your test cases, in the Right hand side pane of the Test Case editor you can see test steps arranged as Data Source, Test Request and Data Source loop.


Click thebutton to run the Test Case, SoapUI will run all the test case, which are present in Data Source until last row.

Once the Test case execution is done you will see the status as “Finished” and in below pane you will see the logs how the test case executed in order, click on the Request in logs pane to see the request and response xmls.

Click on the any “GetGeoIP - Request 1” step in logs pane, a new window opens there you will see Request and Response tabs, click on respected tab to view the details,

Below is the Request XML, which sent with IPAddress,

Response xml, which got from Service/Server, here Server/Service, is our own created Mock Service; the response is same for all the test case, as we have created Static Mock response as below,



Yes, now you are done with Testing of service with use of Mock Service, Here I have done Mock Service testing of service for static values in Mock Response, in my next post I will describe about Dynamic Mock Response.

Please note :-  This is for SoapUI Pro version not SoapUI Open source, It can be done with SoapUI Open Source also only thing is in SoapUI open source there is no Data Source and Data Source Loop feature available. Other than Data Source and Data Source Loop, Adding Request to the Mock Service, configuring the Mock Response with our own values and changing the Mock Service sever settings like Port and Host name is available in SoapUI open source.

So In SoapUI Open Source add request to Mock Service and configure settings and Mock Response, start the mock service/server and change the End Point in request address bar and Run the request, you will see the mock response.
With This…

That’s all Folks.


Monday, June 16, 2014

DataDriven Testing in SOAPUI Open Source WebService Test Tool using Excel File.


DataDriven testing is always comes first when evaluating any test automation tool, and other features depends on the needs for the project. And most of the Test Automation tools which supports DataDriven testing as paid tools I mean to say strictly Licensed, some of the tools are less in License price and some of them are very high, due to this reason all some of the test automation tools creators provides Open Source tools which are less in the features.

Now in this post I am going to describe some technique to DataDriven testing on SoapUI Open Source tool, in which there is no DataDriven feature present. Which helps you in saving License price. (After publishing this post one team will find me for sure, I Am Sorry Team).

So let us start, as you all know how to create project, Test Suite and Test Case (or refer my other post for the same).

In below screen you can see the Project Test Suite and Test Case created. In right pane, you can see the xml, which is actual request xml for the “SendSMSToIndia” request.













Also observe there are totally three fields are present in which we need to enter the data to it from the excel sheet.

        <web:MobileNumber>?</web:MobileNumber>
         <web:FromEmailAddress>?</web:FromEmailAddress>
         <web:Message>?</web:Message>

Now move on to preparing the Input data for the request fields from the excel file, to do that just follow the steps,

Open excel file and create header as same as the fields name, here in our test request we have fields name as above so here header is as below in excel file, ’MobileNumber’, ‘FromEmailAddress’ and ‘Message’.











Now it’s time to prepare the input excel file with required test data, may be Valid or invalid based on the project requirement. After successful update of the test data into the excel file, the file will looks like below.




















Now its time to add import this test data to the request xml by using Groovy script. Write Groovy/Java code to read the Excel file and use the SOAPUI inbuilt library functions and some groovy scripting function to read and assign value to the xml tag in the request xml.
   
To do so add Groovy Script to Test Step to the Test Suite, once you add then your request looks as below,






















Now write the Groovy/Java code to read the excel file data and Groovy. Refer the below screen shot for the code.


Once you done with the writing above code in your Groovy Script in the Test Step, then now its time to execute the Groovy script. When we run the Groovy script this script will read, excel sheet data and assigns the value to the xml respective xml tag in to the Request xml and run or execute the “SendSMSToIndia” request.

Now its time to read the Request’s Response xml. When we execute the “SendSMSToIndia” request then below response is returned by the system,












In the response xml we can see ‘FromEmailAddress’ ,’MobileNumber’, ’Provider’ ,’State’, and ’Status’ are the tags which need to verify in the response. For this need to below lines code to get value from response.







Keep these lines of code inside the for loop, why system reads the each row till last row of the excel sheet input data and assigns to respective tag of the request xml, and once the request executes then system generates the response xml then above code reads the respective or required tags from the response xml. Once you add above code to the Groovy script code then finally script looks like below.



In short Script will read the excel sheet data as cell value (row, column), this values is as same as tag name in the request xml.
Script will read completely content of the xml and stores in the holder. This holder will take above excel cell value to verify the tag is exist in the xml or not, if exist then enter the value and update the xml.
Script will also execute Request for each record in excel until the last row of excel.

Now you can use these parameters which you read from the response xml, and update into the excel sheet just as Report.

Once you done with this then you have saved some more budget to your organization, which you are spending on buying License every year.

 With this…

That’s all Folks.


Wednesday, April 9, 2014

DataBase Testing With SoapUI


Hi All this is my new post on SoapUI which describe about the Database testing in SoapUI tool, which is mainly helps in validating your SoapUI response and the actual value present in Database.
               In this post I will describe how to do Database testing like, how to get connection with Database from SoapUI tool.

Before starting Database testing we have to get connect to the Database from the SoapUI, so we can get connection to the Database in 3 types, here in this post I will describe all 3 types of connection with DataBase from SoapUI.

Type I:- Get Database connection at Project level, by just following below steps.
              
  As I described in my previous post how to create Project, Test Suite and Test Case. Create project and right click on the project you created or double click on it and follow the steps, open the Project View.



Once you select or clicked on ‘Show Project View’ you will see the below screen in the right pane of SoapUI window, and after that click on ‘JDBC Connections’





And you will be seeing JDBC Connection pane in which we have to create New Database Connection, now follow the steps marked in the screenshot, once you click on the “+” sign as marked new popup box open, enter the DB Connection Name, and click OK,



Once you entered the DB Name and Click OK, you will see the below popup where we need to enter database details as shown in the below screenshot 



Click ‘Test Connection’ button to test the Database Connection, once after you filled all correct value into it,  if all the details are correct you will see message as “The Connection Successfully Tested” means successfully connected to the Database.[Here I have selected the Driver as “Oracle Thin/Oracle Jdbc Odbc driver”] as shown in below screenshot,



The same DB Name can be used in the in your Test Case JDBC Request step.


Type II:- Here we will see how directly we get connection to the database from JDBC Request Test Step in the Test Case. Here you can see the above created, DB name you can use the same or you can create new one. Here how it is as shown in below steps.
Add your request to Test Case (Follow my previous post to create Test Case and add request to Test Case). Now add JDBC Request to the test step.


Once you added the JDBC Request to the Test Step, open that step by double clicking or right click and select ‘Open Editor’. Then JDBC Request window will look like below screen.


In above screenshot as you can see the DBConnect name as it was created in the in Type I.

Assume you have not created or not connected to Database at project level, and now you want to connect to the Database at Test Case level, then you can select or Click on “<Create New>” option, once you selected ‘Create New’ you will see below screenshot New JDBC Connection popup box here enter the DB name, here I have entered DB name as ‘NewDBConnect’


Once you Click ok you will see below window, in this you need to enter all the details to get connect to Database.


In above screen you can select any driver as per your need or as per your database, here I have selected Oracle Thin/JDBC driver. As shown in below screen.


Once you selected Driver, after that you need to provide all the details as Hostname, username, password, Port and SID and Click on Test Connection, if you get message as “The Connection Successfully Tested” means successfully connected to the Database. As shown in below screenshot.




Once you click on “OK” button you will see below message box asking for take out to the new window where you need to build the query or select the table or write your own query to retrieve the result. In below screen select ‘Yes’ button you will see the next screen where you will find all the table which are present in your database as per your user access.



Once you are satisfied with your query build and you got the expected result, then just click on OK button,


Now you will come back to same JDBC Request window, and you can also see the query which you built in above screen in JDBC Request. Once you execute this query you will see query result in XML format or in form format in JDBC Request right pane, as shown in below screenshot.



Type III:-
               Now we will see how to connect to Database from the Groovy script, just add the ‘Grooy Script’ test step to your test case as shown in below screen.



Once you added the Groovy Script to the test case, write connect string to connect to database as shown in the below screen.



Here, Type-I and Type-II difference is, In Type-I, we create DB connection at project level then can use the same DBConnect reference throughout the project and use that in JDBC Request. In Type-II its just related to that particular test case and you cannot use outside the test case. This type of connection useful when you have to use different database for each Test Case then this will help you.

I hope this will help you in your project for Database testing.
In next post I will post some useful sql queries to retrieve the data from table in Groovy script.


That’s all Folks.