Forum Discussion

mchelikani's avatar
mchelikani
Contributor
12 years ago

Issue Saving HttpRequest with variables to a File

I have a httprequest where I have some values(Start, End etc) getting from datasource as shown below from spreadsheet. I have a groovy script to store request and responses. The issue I am facing is, once the request is saved shows the same request shown below instead of values getting replaced with data from my datasource.

The TestCase and TestStep are successful. It looks like when it is executed soapui successfully replacing with the values from datasource but when I save the request through below groovy script which is placed in TestRunListener.afterStep Event Handler , it is storing the request as it is. ( The variables in $ in the request are not getting replaced by values as shown in the request below as bold)


DataSource: RegressionData

<soap:Envelope xsi:schemaLocation="http://gcnet/Intranet/cgi-bin/1AXML.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header xmlns="http://www.amadeus.net/1axml-msg/schema/msg-header-1_0.xsd">
<MessageHeader ResponseRequested="true" Terminate="true" Reverse="true" id="095C7130000E8A" version="1.0" soap:mustUnderstand="1">
<From>AVMHOS</From>
<To>1ASRHOS6C2</To>
<TimeStamp>
<GenerationTime>2012-07-25T18:27:06Z</GenerationTime>
</TimeStamp>
<FromRef>
<ID>00C9RXCK4N</ID>
<SequenceNb>1</SequenceNb>
</FromRef>
<Service version="" id="OTA2007A">
<name>OTA_HotelAvailRQ</name>
</Service>
</MessageHeader>
</soap:Header>
<soap:Body>
<OTA_HotelAvailRQ xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" EchoToken="T" Target="Test" Version="2.001" PrimaryLangID="en" SummaryOnly="1" RateRangeOnly="1" xmlns="http://www.opentravel.org/OTA/2003/05">
<POS>
<Source AgentSine="A9999WS" PseudoCityCode="DUBIE38SP" ISOCountry="IE" ISOCurrency="EUR" AgentDutyCode="SU" AirlineVendorID="1A" AirportCode="DUB">
<RequestorID Type="22" ID="00333480" ID_Context="IATA"/>
</Source>
</POS>
<AvailRequestSegments>
<AvailRequestSegment>
<HotelSearchCriteria>
<Criterion ExactMatch="1">
<StayDateRange Start="${RegressionData#StartDate}"/>
</Criterion>
<Criterion ExactMatch="1">
<StayDateRange End="${RegressionData#EndDate}"/>
</Criterion>
<Criterion ExactMatch="1">
<RoomStayCandidates>
<RoomStayCandidate>
<GuestCounts>
<GuestCount AgeQualifyingCode="10" Count="1"/>
</GuestCounts>
</RoomStayCandidate>
</RoomStayCandidates>
</Criterion>
<Criterion ExactMatch="1">
<HotelRef ChainCode="${RegressionData#Brand}" HotelCode="${RegressionData#Brand}${RegressionData#Amadeus}" HotelCityCode="ATL" HotelCodeContext="1A"/>
</Criterion>
</HotelSearchCriteria>
</AvailRequestSegment>
</AvailRequestSegments>
</OTA_HotelAvailRQ>
</soap:Body>
</soap:Envelope>


Groovy Script to Save and Request and Response to File:


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def lastResult = testRunner.getResults().last()
def lastResultName = lastResult.getTestStep().getLabel().toString()
def request = groovyUtils.getXmlHolder(lastResultName + "#Request")
def response = groovyUtils.getXmlHolder(lastResultName + "#Response")
//def response = groovyUtils.getXmlHolder(testStepResult.testStep.Response)

def resultsFolderPath = context.expand( '${resultsPath}' )
def testCaseName = testRunner.testCase.name
def hotel = context.expand( '${RegressionData#Hotel}' )
def testName = context.expand( '${RegressionData#TestName}' )
def corpID = context.expand( '${RegressionData#CorpID}' )

log.info("Request..."+request.getXml())
log.info("Response..."+response.xml)
log.info("resultsFolderPath..."+resultsFolderPath)

def filePath = resultsFolderPath
def requestFileSuffix = "_RQ.xml"
def responseFileSuffix = "_RS.xml"
def fileName = ''

if(testCaseName){
fileName = fileName + testCaseName
}
if(testName){
fileName = fileName +"_" + testName
}

if(hotel){
fileName = fileName + "_" + hotel
}
if(lastResultName){
fileName = fileName + "_" +lastResultName
}
def testcaseRequest = new PrintWriter(filePath + fileName + requestFileSuffix )
def testcaseResponse = new PrintWriter(filePath + fileName + responseFileSuffix )
testcaseRequest.println( request.xml)
testcaseResponse.println( response.getXml())
testcaseRequest.flush()
testcaseRequest.close()
testcaseResponse.flush()
testcaseResponse.close()
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    I believe you can use the following code to read the actual content of the submitted request: context.httpResponse.requestContent.

    Kind regards,
    Manne
  • Thank you for the Reply!

    I tried this and the issue still exists.

    Any other suggestions?

    I had the code in Event Handler as I am saving the Http Request and Response after every step.

    Alternatively, I added another test step with the groovy script you suggested and the issue still same.

    Any other suggestions?

    I basically want to get handle of Submitted Request and Response after Every TestStep.

    Appreciate for all the help!!
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    This works for me: new String(context.httpResponse.rawRequestData)

    Kind regards,
    Manne
  • Hello Manne,
    I tried your suggestion and I see only the following getting printed when I used new String(context.httpResponse.rawRequestData)


    POST http://qa.b2b.ihg.com/b2b/xml/raterange ... hotels.xml HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: text/xml
    Authorization: Basic OTE1NDphbUBkZXUk
    X-Forwarded-For: 82.150.226.126
    Content-Length: 2184
    Host: qa.b2b.ihg.com
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


    -Madhu.
  • Hello Manne,

    To make things much simpler this is what I did. I have created a soapui project which I am going to attach. The issue is getting the RawRequest ( Request that gets submitted to the endpoint url).


    1. Attached Project File (IHG-B2B-soapui-project.xml)
    2. Attached Spredsheet (Excel) file where the source for Parameterized Requests for XML ( Regression_Data.xls)
    3. Attached Screenshots showing the Issue ( Issues.doc)


    To Run[/b

    1. Please go to TestStep "RegressionData" modify the file location to wherever you downloaded the Regression_Data.xls at #2.
    2. Please Observe the Code I put in TestRunListener.afterStep event handler.
    2. Please run Amadeus TestCase and Observe the output in scriptlog where I am printing the raw request. Observe that the raw request shows the parameterized values and does not show the values actually got submitted. (please look at the screenshots provided in the Issues.doc which is attached)


    Thanks for the help so far.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    I tried the project you supplied and I also tried Mannes suggestion which for me seems to work fine.
    I do get the headers, as you said, but I also get the rest of the request body printed to the log.
    Can you please try this again just to be sure?

    Thanks,
    Anders
    SmartBear Sweden
  • The Request is getting printed. The issue is, the parameterized variables are not getting replaced.

    Please observe my screenshots which I attached and log.info which is getting printed to soapuilog.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Sorry for not being clear.
    What I meant in my previous response was that when I do like Manne suggested and print
    new String(context.httpResponse.rawRequestData)
    instead of
    groovyUtils.getXmlHolder(lastResultName.trim() + "#RawRequest")
    it does indeed replace the variables.

    Regards,
    Anders
    SmartBear Sweden
  • Thanks Anders!

    Is there anyway I could get just request without header information when there are variables ( Request Data is parameterized)?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi

    Although I cannot guarantee that there is no way of getting only the request body I think that is the case. A workaround could be to get the full request data and then remove everything before the empty row that separates the headers and the body in the script.

    Regards
    Joel Jonsson
    SmartBear Sweden