Web Services:-
Web Services is a web based integrated application
which uses XML,WSDL,SOAP,UDDI Standards over an internet protocol primarily
used as a means for business communicate with each other and with clients, Web
services allow organizations to communicate data
without intimate knowledge of each other's IT systems behind the firewall.
XML is the language used to Tag the data, SOAP (Simple
Object Access Protocol) is used to transfer the data, WSDL (Web Services
Description Language) is used for describing the services available UDDI is used
for listing what services are available.
In simple words we can say that “Web services are open
standard (XML, SOAP, HTTP etc.) based Web applications that interact with other
web applications for the purpose of exchanging data”
Note that web services is not UI based application.
QTP:-
QTP or quick test professional is an automated user
interface testing tool that allows testing of web based or distinct computer
applications.
QTP basically have the scripting language used as “VB
Script” which can be used to specify the test procedure.
QTP AND WEBSERVICES
Here before going in blending of QTP and Web Services,
let us see the scope of web services and its advancements.
Note:-For performing web services testing using QTP make sure that
the web Services add in is installed or QTP 9.5+ version is used.
As discussed above that web services used XML to tag
the data. Basically a web service consists of data values organized in the form
of tree structure written in XML language.
Let us consider an example to understand web services
more easily.
Suppose we need to search employee details in the
“Sparsh” through telephone directory having some URL like http://sparsh. We
provide either of employee ID or name or email etc as an input and click on
search button to request and get the employee details as a response. Here input
selection page of telephone directory is request page and employee details page
is response page.
Similarly in web services, we have request XML and
response XML. In request XML we can have multiple set of optional or required
input values.But there is no interface page
<?xmlversion="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Bodyxmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>Infosys</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
Above is the example of request XML where “Infosys” is
provided as input.
Every web services is associated with a WSDL URL, for
eghttp://www.webservicex.net/country.asmx?wsdl.
Any web services can be associated with one or more
operations (Requests). For example web services URL http://www.webservicex.net/country.asmx?wsdl. Can have several operations like
“GetCountries”,”GetCurrencycode”,”GetISD”.
Various Approaches for performing Web Services through
QTP
There are two ways how we can perform web service
testing through QTP.
1) Data
Driven Framework using XML Request – Response
2) Data
Driven Framework using XML Checkpoints
We
Will jolt in to the testing ways individually by setting with an example.
Data Driven Framework using XML Request –
Response
This is the most used way of doing the web service
testing. Pre-Requisite for this method is that Request XML should be ready.
In this method we have to create the request xml of
our own, and then the request XML is send to the web service URL and then the
response is then saved to perform analysis. We will see an example to see how
it is done
After opening the QTP click on the Web Service Wizard
icon as shown above
Click on the Next Button
Provide the WSDL URL in the URL radio button and click
on the next button
After that Select the operations which we need to
perform testing.
Please note uncheck the option Add XML checkpoint when
asked at the last of the wizard.
After clicking on the Finish button on the wizard , we
will see the set of codes on the QTP screen. The wizard actually adds the
selected operation object in the object repository.
'Declare the object for the webservices
Set sWebServices =
WebService("MetricWeightUnitService")
Set sXmlFile =
XMLUtil.CreateXML()
sXmlFile.LoadFilestrXMLRequestLoc
sXmlString = sXmlFile.ToString
sWebServices.SendRequest
"ChangeMetricWeightUnit",sXmlString
Set sFileSysObj = CreateObject("Scripting.FileSystemObject")
Set sFile =
sFileSysObj.OpenTextFile(strXMLResponseLoc,2,True)
sFile.Write(sWebServices.LastResponse)
sFile.Close
Set sFile=nothing
Set
sFileSysObj=nothing
Explanation of code:- First line of the code is where
we are creating the object for web service having operation naming “MetricWeightUnitService”
Next three lines of the code is used to convert the
XML request in the form of String. Note that strXMLRequestLocis the variable where we need to the set the path where
the request XML is placed.
When the request XML is converted in to string form
then the request is send to the web services URL by SendRequest property.
Response for the request is captured by using
LastResponse property.
Above example shows how we have send the request and
noted down the response.
Attached below are the Request and Response XMLs
reseived.
By this method we can easily capture the response or
the analysis what we want to perform.
Note that parsing of the XML response will be covered
after the explanation of XML checkpoint testing strategy method.
2)
Data Driven Framework using XML Checkpoints
In this testing strategy also we have to way perform
through the Web service Wizard. Only difference is that we have to check the
option “Add XML checkpoint” at the end of the web service wizard. For the same
web service operation “MetricWeightUnitService” we will have the XML checkpoint method.
Lets have a look at the code below:-
DataTable.AddSheet("GetData")
DataTable.ImportSheet
"C:\Sheet1.xls","Parameter","GetData"
DataTable.ImportSheet"C:\Sheet1.xls
","ExpectedData","Action1"
Environment.Value("iWeight")=""
Environment.Value("sFrom")=""
Environment.Value("sTo")=""
iRowCounter=DataTable.GetSheet("GetData").GetRowCount
iModeCounter=1
Do until
iModeCounter>iRowCounter
DataTable.GetSheet("GetData").SetCurrentRow(iModeCounter)
DataTable.GetSheet("Action1").SetCurrentRow(iModeCounter)
Environment.Value("iWeight")=DataTable.Value("Weight","GetData")
Environment.Value("sFrom")=DataTable.Value("From","GetData")
Environment.Value("sTo")=DataTable.Value("To","GetData")
ChangeMetricWeightUnit
= WebService("MetricWeightUnitService").ChangeMetricWeightUnit(Environment.Value("iWeight"),Environment.Value("sFrom"),Environment.Value("sTo"))
WebService("MetricWeightUnitService").Check
CheckPoint("ChangeMetricWeightUnit")
iModeCounter=iModeCounter+1
Loop
The first line of the code is used to add the sheet to
the data table which consists of the input parameters to be send the web
service.
Second line is used to import the datasheet of the
input values and third line is used to import the data sheet where the values
are expected and are passed to the XML checpoints.
Now open the XML checkpoint wizard as shown below
As shown above
the expected valued is passed to the checkpoint by fetching the value directly
through data table.
ChangeMetricWeightUnit
= WebService("MetricWeightUnitService").ChangeMetricWeightUnit(Environment.Value("iWeight"),Environment.Value("sFrom"),Environment.Value("sTo"))
WebService("MetricWeightUnitService").Check
CheckPoint("ChangeMetricWeightUnit")
Above code is the building block of the XML checkpoint
testing strategy.
As the first line is used to hit the web service for
the selected operation with the set of input values.
As the XML checkpoint is having the expected value
through the Data table , second line states that the XML checkpoint will
compare the expected and actual values.
This is how XML Checkpoint strategy to perform the web
service is done.
4 comments :
I think the things you covered through the post are quiet impressive, good job and great efforts. I found it very interesting and enjoyed reading all of it...keep it up, lovely job..
utah custom web design
It's outstandingly useful site for learn. This present information's are to a great degree valuable to us. It will upgrade my knowledge. Thankful to you for sharing this sublime site.
Performance testing training in Chennai | LoadRunner Training Institute in Chennai | HP LoadRunner Training in Chennai | LoadRunner Classes in Chennai
Nice blog has been shared by you. it will Thank you for sharing this blog.be really helpful to many peoples who are all working under the technology.
iosh course in chennai
we live in.
good work done and keep update more.i like your informations and that is very much useful for readers.
Microsoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
Post a Comment