Forum Discussion

Bala_1980's avatar
Bala_1980
Occasional Contributor
9 years ago

I want to store the entire xml response in the specified location

Hi, I want to store the entire xml response in the specified location as it is (which includes the xml tags). Pl. help.

  • KarelHusa's avatar
    KarelHusa
    Champion Level 2

    You can store all requests and responses of the test steps included in a test case with the following script.

     

    You need to:

    1. set the TearDown script of the test case to the code bellow.

    2. define the 'outputDirectory' property on the project level to the required path, e.g. /C:/testing/out

     

    File outDir = new File(testRunner.testCase.testSuite.project.getPropertyValue( "outputDirectory") + "/" + testRunner.testCase.testSuite.getName() + "/" + testRunner.testCase.getName())
    outDir.mkdirs()
    File reponseFile
    File requestFile
    testRunner.results.each { // WsdlTestRequestStepResult
    	requestFile = new File(outDir, it.getTestStep().getName() + "-Request.xml")
    	responseFile = new File(outDir, it.getTestStep().getName() + "-Reponse" + "-" + it.getStatus() + ".xml")
    	requestFile << it.getRequestContent() 
    	responseFile << it.getResponseContent()
    }

     

  • Bala_1980's avatar
    Bala_1980
    Occasional Contributor

    Hi, how to store the entire xml responses in the specified location by using Groovy Scripting.

  • nmrao's avatar
    nmrao
    Champion Level 3

    Create a test case level custom property, say FILE_PATH and provide the value say 'c:/temp/myfile.xml'

    Please use script assertion for the request test step.

     

    //Check the response is not empty
    assert context.response, "Response is empty or null"
    //Save response
    new File(context.testCase.getPropertyValue('FILE_PATH')).write(context.response)
  • nmrao's avatar
    nmrao
    Champion Level 3
    Did you try below for single response? Then add the same for different tests for multiple occurrences.
    • Bala_1980's avatar
      Bala_1980
      Occasional Contributor

      Hi, its working now with the following lines of code:

       

      def myOutFile = "File Path"
      def response = context.expand( '${Methodname#Response}' )
      def myOutFile1 = new File(myOutFile)
      myOutFile1.write(response, "UTF-8")