Share this page

# Enhance a recorded session with XML

You can prepare an XML script by recording a session and then manually adding the relevant XML and Vuser API functions.

The following example illustrates how a recorded session was enhanced with Vuser API functions. Note that the only function that was recorded was web_submit_data, which appears in bold.

The first section contains the XML input declaration of the variable SOAPTemplate, for a SOAP message:

    #include "as_web.h"
    // SOAP message
    const char* pSoapTemplate=
      "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
          "<soap:Body>"
              "<SendMail xmlns=\"urn:EmailIPortTypeInft-IEmailService\"/>"
          "</soap:Body>"
      "</soap:Envelope>";

The following section represents the actions of the user:

Example:

    Action1()
    {
    // get response body
     web_reg_save_param("ParamXml", "LB=", "RB=", "Search=body", LAST);
    // fetch weather by HTTP GET
    web_submit_data("GetWeather","Action=http://glkev.net.innerhost.com/glkev_ws/
         WeatherFetcher.asmx/GetWeather",
          "Method=GET",
          "EncType=",
          "RecContentType=text/xml",
          "Referer=http://glkev.net.innerhost.com/glkev_ws/WeatherFetcher.asmx?op=GetWeather",
            "Snapshot=t2.inf",
            "Mode=HTTP",
             ITEMDATA,
            "Name=zipCode", "Value=10010", ENDITEM,
             LAST);

    // Get City value
      lr_xml_get_values("Xml={ParamXml}",
                     "Query=City",
                     "ValueParam=ParamCity",
                     LAST
        		    );
     lr_output_message(lr_eval_string("***** City = {ParamCity} *****"));

    //Get State value
     lr_xml_get_values("Xml={ParamXml}",
                     "Query=State",
                     "ValueParam=ParamState",
                     LAST
        		    );
     lr_output_message(lr_eval_string("***** State ={ParamState}*****"));

    // Get several values at once by using template

    lr_xml_get_values_ex("Xml={ParamXml}",

    "Template="
                "<Weather>"
                   "<Time>{ParamTime}</Time>"
                   "<Temperature>{ParamTemp}</Temperature>"
                   "<Humidity>{ParamHumid}</Humidity>"
                   "<Conditions>{ParamCond}</Conditions>"
                "</Weather>",
             	LAST
        		);

       lr_output_message(lr_eval_string("***** Time = {ParamTime},
                     Temperature =  {ParamTemp}, "
                        "Humidity = {ParamHumid},
                     Conditions = {ParamCond} *****"));

     //Generate readable forecast
        lr_save_string(lr_eval_string("\r\n\r\n*** Weather Forecast for {ParamCity},
                 {ParamState} ***\r\n"
              "\tTime: {ParamTime}\r\n"
              "\tTemperature: {ParamTemp} deg. Fahrenheit\r\n"
              "\tHumidity: {ParamHumid}\r\n"
              "\t{ParamCond} conditions expected\r\n"
              "\r\n"),
              "ParamForecast"
        );
        // Save soap template into parameter
        lr_save_string(pSoapTemplate, "ParamSoap");

    // Insert request body into SOAP template
        lr_xml_insert("Xml={ParamSoap}",
             "ResultParam=ParamRequest",
             "Query=Body/SendMail",
             "position=child",
             "XmlFragment="
                 "<FromAddress>john1@mydomain.com</FromAddress>"
                 "<ToAddress>softwaresupport@mydomain.com</ToAddress>"
                 "<ASubject>Weather Forecast</ASubject>"
                 "<MsgBody/>",
     LAST);
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"  "<soap:Body>""<SendMail xmlns=\"urn:EmailIPortTypeInft-IEmailService\"/>""<FromAddress>john1@mydomain.com</FromAddress>"
             "<ToAddress>softwaresupport@mydomain.com</ToAddress>"
             "<ASubject>Weather Forecast</ASubject>"
             "<MsgBody/>"
          "</SendMail>"
       "</soap:Body>""</soap:Envelope>";

    // Insert actual forecast text
        lr_xml_set_values("Xml={ParamRequest}",
                          "ResultParam=ParamRequest",
                          "Query=Body/SendMail/MsgBody",
                          "ValueParam=ParamForecast",
                           LAST);

    // Add header for SOAP
     web_add_header("SOAPAction", "urn:EmailIPortTypeInft-IEmailService");

    // Get response body
     web_reg_save_param("ParamXml", "LB=", "RB=", "Search=body", LAST);

    // Send forecast to recipient, using SOAP request
     web_custom_request("web_custom_request",
       "URL=http://webservices.matlus.com/scripts/emailwebservice.dll/soap
            /IEmailservice",
            "Method=POST",
            "TargetFrame=",
            "Resource=0",
            "Referer=",
            "Body={ParamRequest}",
            LAST);

    // Verify that mail was sent
        lr_xml_find("Xml={ParamXml}",
                    "Query=Body/SendMailResponse/return",
                    "Value=0",
                     LAST);
        return 0;
    }

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1-26.3 All View Local Help Center View Online Help Center Version: