Forum Discussion

badfeelings's avatar
badfeelings
New Contributor
9 years ago

Write log file from all loop request when executing test-case

I'm new in SOAP UI testing and I have one questions according to log files. I have wrote groovy script, which with loop make some requests, and I need to write all requests result in one txt file. Maybe some suggestions from experienced users, please? :)

Thank you!

 

P.S - Maybe I can somehow automatically with groovy script save http log after request is done?

  • KarelHusa's avatar
    KarelHusa
    9 years ago

    Hi,

    I put the logging into a tearDownScript and go through all results of the test steps included in the test case.

     

    I log the content of the request and response:

     

     

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

     

     

    You can also make a simple reporting CSV, which contains a status for each test step, e.g. (the iterator 'it' goes over testRunner.results):

     

     

    def resultLine = testRunner.testCase.testSuite.getName() + ":" + testRunner.testCase.getName() + ":" + it.getTestStep().getName() + ":" + it.getStatus() + ":"

     

    The code above belongs to WSDL/SOAP services, co you may need to accomodate it for REST.

     

    Karel

     

     

    • badfeelings's avatar
      badfeelings
      New Contributor

      I'm testing REST API service in Swagger. With groovy script I have loop method, which update some information by sending request, and I need to write log file, where someone can see what kind of request there was and details for example.

      • KarelHusa's avatar
        KarelHusa
        Champion Level 1

        Hi,

        I put the logging into a tearDownScript and go through all results of the test steps included in the test case.

         

        I log the content of the request and response:

         

         

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

         

         

        You can also make a simple reporting CSV, which contains a status for each test step, e.g. (the iterator 'it' goes over testRunner.results):

         

         

        def resultLine = testRunner.testCase.testSuite.getName() + ":" + testRunner.testCase.getName() + ":" + it.getTestStep().getName() + ":" + it.getStatus() + ":"

         

        The code above belongs to WSDL/SOAP services, co you may need to accomodate it for REST.

         

        Karel