mchelikani
12 years agoContributor
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()
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()