Monday, 15 February 2016

Working with SoapUI Projects

 

Creating a new project by adding the WSDL:
#1. Open SoapUI application and follow the instructions to proceed with the license process
#2. Click New SOAP Project option from File menu or press CTRL+N shortcut key.
#3. Enter the project name (meaningful one is better)
#4. Then specify the valid WSDL URL in the given text box. Let’s use currency converter URL. i.e. http://www.webservicex.com/CurrencyConvertor.asmx?wsdl. (There are many other sample WSDL urls available. Please check for the open source Web services available for variety)
#5. The remaining setting can be left default and then click OK. The below WSDL processing progress shows up (Note: internet connection is mandatory for this to work)
SOAPUI Project 1
#6. Once WSDL URL processing has been successful, SOAP project will be created along with the service requests.
The URL we used in this tutorial can be called from anywhere through Internet. This web service is hosted on a web server and on calling the URL the hosted server is searched and SoapUI project gets loaded with the services contained within it as you can see below:
SOAPUI Project 2
Project creation done!
Adding a WSDL to an existing project:
#1. Right click on the Project Name in the Navigator panel
#2. Click Add WSDL option or hit CTRL + U
#3. Add WSDL dialog appears on the screen.
#4. Enter valid WSDL URL in the text field as seen below:
SOAPUI Project 3
#5. Click OK
#6. The URL is processed and the respective services get loaded into the SOAP project as below:
SOAPUI Project 4
Executing Services & Response Verification:
#1. Expand the CurrencyConvertorSoap in the tree (click on the +)
#2. Double Click Request1 (the service name, this can be changed if needed)
Please take a look at the screenshot for more information: (Click on image for an enlarged view)
SOAPUI Project 5
#3. Click on the XML tab from request section. It will show the input request for currency convertor web service as shown here in the screenshot. (Click on image for an enlarged view)
SOAPUI Project 6
In the above screen question mark (?) symbols are in the input request. These are the input parameters for the currency convertor web service.
When run / start a icon is clicked, SoapUI will call the currency convertor web service along with the input parameters that were provided in the request. Then, the web server will receive these input parameters and process them. Once done, the server will send the response back to SoapUI.
Sometimes the response may contain error messages. For example, while processing the input request, server may be down or Internet connection could not be established from our side. During that time, we will get a response that is an exception.
For instance, let us enter USD for <<From Currency>> and INR for <<To Currency>> with valid values as below and call the service. As can be seen below, the correct response is obtained.
(Click on image for an enlarged view)
SOAPUI Project 7
To test a negative scenario, let me change the <<From Currency>> as US and execute the service.
(Click on image for an enlarged view)
SOAPUI Project 8
To this we received an unknown error messages because our input was wrong. The same error messages will be shown in the error log tab.

TestSuite, TestCase and TestStep in SoapUI:

A test suite is a common repository that contains a number of test cases. It is a collection of Test cases that represent the application flow. Test cases are the descriptive data about the application flow. Each test case contains individual actions called Test steps.
In SoapUI, test suite will be a root node that has to be created explicitly and test cases can be added under it and to test cases we can add test steps. It is a tree structure of sorts. If the test suites are well built, a bunch of webservices can be executed in one go. These test suites can be used for smoke, performance, regression testing etc. Once executed SoapUI Pro generates a report for analyzing results.
Adding a TestSuite during project creation:
#1. Click New SoapUI Project option (or press CTRL + N) from File menu. Check the options as above and click OK.
SOAPUI Project 9
#2. Another pop-up to set the test case details would be displayed, set the properties as below, and click OK
#3. Enter the TestSuite name. By default, a sample name will be automatically assigned and that can be changed. Lets say it is: CurrencyConvertorSoap_TestSuite1 and click OK
#4. Based on the services count under the project, it will add that many test suites. Multiple test suites can be created.
 

Saturday, 13 February 2016

Reading and Writing on Excel sheet in CodedUI uisng EPplus component

How to read and write values in Excel sheet
Here I am explaining you the easiest way to play with Excel sheet using codedUI.We are using a third party component for this purpose and its Epplus

Step 1:Down load Epplus from the above link and save it in your machine

Step2:Add reference on your project by right clicking your project in the solution explored

Step3:Add following namespaces in your project
using OfficeOpenXml;
using OfficeOpenXml.Drawing

Step4:In the code part add the following code
FileInfo templateFile = newFileInfo(@"C:\Sample2.xlsx");//Create a fileinfo object
ExcelPackage package = newExcelPackage(templateFile);//Create excel package and pass the fileinfo object to it
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];//Create Worksheet
worksheet.Cells[1,1].Value = Value;//Writes value to cell(1,1)
Package.Save();//Save the data in excel

Coded UI Data Driven automation - Working with excel data using OLEDB connection


//Create and excel sheet in your machine and copy the path to Data source in connection string if the HDR property is set to YES.Then the deader of the excel column can be specified in the SQL statements 

//The string below needs to be there for establishing OLEDB connection for .Xls files
string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myexcel.xls;" +
@"Extended Properties='Excel 8.0;HDR=Yes;'";

//Creating a Oledb connection and passing the connection string
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();//Need to open the connection first

//Create command object and pass connection object and sql statements as arguments to perform operations 
OleDbCommand command = new OleDbCommand("update [Hisham$C1:C6] set Salary = '25000'",connection);

//This statement is for executing the above statement and put the data in data reader object
OleDbDataReader dr = command.ExecuteReader()

//Below loop is just to read all dataq from the data reader and write on the console
while (dr.Read())//Loop used to output the data from data reader
{
       var row1Col0 = dr[0];
        var rowcol1 = dr[1];
       Console.WriteLine(row1Col0);
       Console.WriteLine(rowcol1);
}

connection.Close();//Close the connection or rather cleaning
}
}

----------------------------------------------------------------------------------------------------------------------------------

//Below statements are oledb statements using for crud operations in C# Excel data processing

//Select all the data from the sheet 1
//OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);

//Update the values in columns C1 to C6 in sheet1
OleDbCommand command = new OleDbCommand("update [Sheet1$C1:C6] set Salary = '25000'",connection);

//Fetch the data from column A4 of sheet1
//OleDbCommand command = new OleDbCommand("select * from [Sheet1$A4:A4]", connection);

//Update the Name and Salary of the employee with ID 's'
//OleDbCommand command = new OleDbCommand("Update [Sheet1$] Set salary='10000',name='Rajesh' where id='s'", connection);