LoadRunner Test WebService A total of 3 ways: 1, through the Web_service_call function, that is, the way to import the WSDL file or URL, 2, through the Soap_request function, through the import XML file to achieve; 3, The script is implemented via the HTTP protocol.
The first can be accessed: http://gungun.blog.51cto.com/9585287/1591100
Today's focus is on the second, importing the XML file via import soap to implement a call to the WebService interface.
The following are examples of weather forecasts that are well known to all:
Interface Url:http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx for weather forecasts
Call the Getweatherbycityname method.
Open the Http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx?op=getWeatherbyCityName page, as shown in the following image:
Save the portion of the red box below into an XML file, and import the XML file just as shown in the following illustration:
The following code is automatically generated after import:
Soap_request ("Stepname=soap request",
"Url=http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx",
"Soapenvelope="
"<soap12:envelope xmlns:xsi=\" http://www.w3.org/2001/xmlschema-instance\ "xmlns:xsd=\" http://www.w3.org/2001/ Xmlschema\ "xmlns:soap12=\" http://www.w3.org/2003/05/soap-envelope\ ">"
"<soap12:Body>"
"<getweatherbycityname xmlns=\" http://webxml.com.cn/\ ">"
"<theCityName>string</theCityName>"//Fill in the city's name here
"</getWeatherbyCityName>"
"</soap12:Body>"
"</soap12:Envelope>",
"Soapaction=getweatherbycityname",
"Responseparam=response",
"Snapshot=t1418827945.inf",
last);
Then add the header information before the code that you just generated. What needs to be added is shown in the first diagram, where "content-length" does not need to be added.
The code that needs to be added in this example is as follows:
Web_add_header ("POST",
"/webservices/weatherwebservice.asmx http/1.1");
Web_add_header ("Host",
"webservice.webxml.com.cn");
Web_add_header ("Content-type",
"Application/soap+xml; Charset=utf-8 "); The note here is a little different from the screenshot.
Web_add_header ("SOAPAction",
"\" Http://webxml.com.cn/getweatherbycityname\ "");
This is done simply by testing the webservice with the Soap_request function.
After fetching the XML data returned by webservice, you can use XPath to validate the data, and LR provides several functions for working with XML:
Lr_xml_get_values ()//retrieves values of XML elements found by a query
Lr_xml_set_values ()//sets the values of XML elements found by a query
Lr_xml_extract ()//extracts XML string fragments from an XML string
Lr_xml_delete ()//deletes fragments from an XML string
Lr_xml_replace ()//replaces fragments of an XML string
Lr_xml_insert ()//inserts a new XML fragment into an XML string
Lr_xml_find ()//verifies that XML values is returned by a query
Lr_xml_transform ()//applies extensible Stylesheet Language (XSL) transformation to XML data