Forum Discussion

dinojadhav's avatar
dinojadhav
Occasional Contributor
4 years ago

Request is not captured with the groovy script showing NULL

Hi All,

 

I have the below script to generate a log file of a complete Test case however, the request is not at all captured dont know what exactly the issue is :

 

Below is the script :

 

import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder
import jxl.*;
import jxl.write.*
import org.apache.commons.lang.StringUtils


def Time = new Date().format("dd-MMM-yyyy h_mm_ss a")
def directory = testRunner.testCase.testSuite.project.getPropertyValue("Logs")
File fold = new File (directory)
fold.mkdir ()

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//Project Name:
def ProjectName=testRunner.testCase.testSuite.project.name

//TestSuite Name:
def TestSuiteName=testRunner.testCase.testSuite.name

//Test Case Name:
def TestCaseName=testRunner.getTestCase().getName()

//Creating File
def responseFile = new File (directory,TestCaseName+"_${Time}"+".txt")

def TestCaseDescription = testRunner.testCase.getDescription()
responseFile.append ("Project Name :${ProjectName}\n\n")
responseFile.append ("TestSuite Name :${TestSuiteName}\n\n")
responseFile.append ("TestSuite Name :${TestCaseName}\n\n")

//def testCaseCount = testRunner.testCase.testSuites[TestSuiteName].getTestCaseCount()

def count = testRunner.testCase.getTestStepCount()

for (i=1;i<count;i++){

def StepName = testRunner.testCase.getTestStepAt(i).getName()

if (StepName.toString()== "GetUpdateToken" ||
StepName.toString()== "Delay" ||
StepName.toString()== "Logfile" )

log.info StepName
else if (StepName.toString()== "GetReservation"
|| StepName.toString()== "UpdateReservation_Add_Hotel_Segment")
{
log.info StepName
responseFile.append ("TestStep Name :${StepName}\n")
def requestName = "\n****************REQUEST****************\n\n"
responseFile.append(requestName, "UTF-8")
def request = testRunner.testCase.testSteps[StepName].testRequest.response.getRequestContent()
//log.info request
responseFile.append(request, "UTF-8")

def responseName = "\n\n****************RESPONSE****************\n\n"
responseFile.append(responseName, "UTF-8")

def response = testRunner.testCase.testSteps[StepName].testRequest.response.getResponseContent()
//log.info response.toString()
responseFile.append(response, "UTF-8")
responseFile.append("\n\n")
}

else{
def RQHolder = groovyUtils.getXmlHolder(StepName.toString()+"#Request")
RQHolder.namespaces["xmlns"] = "http://webservices.sabre.com/sabreXML/2003/07"
def nodeRQ = RQHolder.getNodeValue("//xmlns:SabreCommandLLSRQ/xmlns:Request/xmlns:HostCommand")

def RSholder = groovyUtils.getXmlHolder(StepName.toString()+"#Response")
RSholder.namespaces["xmlns"] = "http://webservices.sabre.com/sabreXML/2003/07"
def nodeRS = RSholder.getNodeValue("//xmlns:SabreCommandLLSRS/xmlns:Response")

def Name = testRunner.testCase.testSuite.getName()
responseFile.append (context.expand(StepName.toString()+ "Step Request: ${nodeRQ}\n"))
responseFile.append (context.expand(StepName.toString()+ "Step Response: ${nodeRS}\n\n"))


}
}

 

In log file the request is showing NULL.

 

 

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    groovy script don’t have a response value, they have a result value.  You might have to check the step type (e.g. request or groovy script) and then decide whether to look for #response or #result.

    • dinojadhav's avatar
      dinojadhav
      Occasional Contributor

      Hi Chris,

       

      I am a bit new to groovy and correct me if I am wrong here. Below is the sameple request and response :

      Here Add Itinerary is my Test Step Name and which execute 01Y5 command and the line " 1 ET 105Y......" is the response of that command. In my case I am getting result as " Add Itinerary  : NULL"    means the command is not captured : 

      Add Itinerary  : 01Y5
      Add Itinerary  : 1 ET 105Y   07JUN M MQXADD SS1   255P  420P /E
                                     ARR-TERMINAL 1

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 3

        Hi,

         

        Is the below code snippet the part that is not working?

         

        def RSholder = groovyUtils.getXmlHolder(StepName.toString()+"#Response")
        RSholder.namespaces["xmlns"] = "http://webservices.sabre.com/sabreXML/2003/07"
        def nodeRS = RSholder.getNodeValue("//xmlns:SabreCommandLLSRS/xmlns:Response")

         

        Do you have other requests that go down this branch and if so, do they return the response?