lr_xml_find function example

In this lr_xml_find function example you will learn how to use lr_xml_find in LoadRunner Vugen script.The lr_xml_find function verifies that whether XML values return by the server which will contains a specified query or not,simply lr_xml_find verifies the XML values with the help of XML Query.

Also READ:

Create a Script for REST API
Create GOAL Oriented Scenario

lr_xml_find function example

Syntax

lr_xml_find(List of specifications ,List of optional specifications , LAST);
List of Specifications

For the following list of required specifications, use the following string format:

ALSO READ  Web Services Scripting Using Loadrunner

lr_xml_find(“XML=response”,
“Query=return/msg”,
“Value=success”,LAST);

Query: the XML Query or The Fast Query on the input XML string.
XML: the XML Input String to perform a query.

Choose one of the following:

Value: the string to find. This can be the element value or its attribute value. or you can use as ValueParam: the parameter name consists of a string to find in XML response.

Example of lr_xml_find

Here I am using CreateFlight order SOAP request to find the XML response and verifying the response data as per given response.

ALSO READ  Loadrunner Actions

WebService Script

CreateFlightOrder Request

web_service_call( “StepName=CreateFlightOrder_101”,
“SOAPMethod=HPFlights_Service|FlightsServiceMethods|CreateFlightOrder”,
“ResponseParam=response”,
“Service=HPFlights_Service”,
BEGIN_ARGUMENTS,
“ExpectedResponse=SoapResult”,
“Snapshot=t1476592590.inf”,
“xml:FlightOrder=”
“<CustomerName>Sujith Kumar</CustomerName>”
“<FlightOrder>”
“<Class>EconomyEconomy</Class>”
“<DepartureDate>2016-10-18</DepartureDate>”
END_ARGUMENTS,
“<FlightNumber>1089</FlightNumber>”
“<NumberOfTickets>1</NumberOfTickets>”
“</FlightOrder>”,
BEGIN_RESULT,
LAST);
“CreateFlightOrderResult/OrderNumber=Param_OrderNumber”,
“CreateFlightOrderResult/TotalPrice=Param_TotalPrice”,
END_RESULT,

 

Actual Response

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”>
<s:Body>
<CreateFlightOrderResponse xmlns=”HP.SOAQ.SampleApp”>
<CreateFlightOrderResult xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<OrderNumber>18</OrderNumber>
<TotalPrice>196</TotalPrice>
</CreateFlightOrderResult>
</CreateFlightOrderResponse>
</s:Body>
</s:Envelope>

In above response we are going to verify OrderNumber is created or not as below.

Action()
{
web_service_call( “StepName=CreateFlightOrder_101”,
“SOAPMethod=HPFlights_Service|FlightsServiceMethods|CreateFlightOrder”,
“ResponseParam=response”,
“Service=HPFlights_Service”,
BEGIN_ARGUMENTS,
“ExpectedResponse=SoapResult”,
“Snapshot=t1476592590.inf”,
“xml:FlightOrder=”
“<CustomerName>Sujith Kumar</CustomerName>”
“<FlightOrder>”
“<Class>EconomyEconomy</Class>”
“<DepartureDate>2016-10-18</DepartureDate>”
END_ARGUMENTS,
“<FlightNumber>1089</FlightNumber>”
“<NumberOfTickets>1</NumberOfTickets>”
“</FlightOrder>”,
BEGIN_RESULT,
LAST);
“CreateFlightOrderResult/OrderNumber=Param_OrderNumber”,
“CreateFlightOrderResult/TotalPrice=Param_TotalPrice”,
END_RESULT,

ALSO READ  Effort Estimation template for performance testing

lr_xml_find(“XML={CreateFlightOrder_101_Response}”,
“Query=CreateFlightOrderResult/TotalPrice”,
“Value=196”,LAST);
return 0;
}

Run the script by press F5 or Reply – Run,it will display Test Results in Reply status and Test Results window as below.
lr_xml_find function example

Script Reply Summary

lr_xml_find function example

Script Reply Log

lr_xml_find function example

What have you learned?

1.What is lr_xml_find function.
2.Syntax of lr_xml_find function.
3.How to write lr_xml_find to verify the XML response.
Please provide your valuable comments on this post,i hope you got enough knowledge on this topic,Thank you for reading Loadrunner Tutorial.

Rajesh

Rajesh has over 8+ years of experience in Quality Assurance (Automation/ Manual). I've completed his B.Texh. He is an experienced software tester,work experience include working on tools like TestNG, Sikuli, Autoit, Selenium Builder and Appium, has worked on various projects from verticals like Retail, Insurance, Tolling and many more and passionate about designing Automation Frameworks that are effective and easy to maintain using Selenium Java.

One thought on “lr_xml_find function example

  1. Please let me ask you a dought regarding text virification we have to give static text for verification right? otherwise if we run with some othe data it wont work? one dought is my response is not only html tags it is comming mixing of someother . is there any way to setup to get in tags format only?

    Please help me in webservice scripting how to down load file?

Comments are closed.