Forum Discussion

arunbharath's avatar
arunbharath
Contributor
4 years ago
Solved

How to get a test-step response from Suite TearDown script?

Hi All. I trying to get step step response of each test case from suite TearDown script.

def testCaseCount = runner.testSuite.getTestCaseCount()
for (int i=0;i<testCaseCount;i++){

	def testCaseName = runner.testSuite.getTestCaseAt(i).getName()

             def testStepCount = runner.testSuite.getTestCaseAt(i).getTestStepCount()

             for (int j=0;j<testStepCount;j++){

             	def testStepName = runner.testSuite.getTestCaseAt(i).getTestStepAt(j).getName()
             	 // log.info(testStepName)

					if (testStepName == "SendPayment"){

						def request=context.expand('${SendPayment#Response}')
						log.info(request)
					}

					
					
					//File f = new File(projectProperty+"/TearDownScriptFiles/"+testCase.name+".json")
					//f.write(response)

             	  
             }
	   
	log.info(testCaseName)
}

Above is my groovy code. I'm iterating all the testcases under suite and test step as well, I'm trying to get the test-step response based on the test step name. Right now I'm able to iterate the test cases and test steps but I could get the test step response..I belive I need to change below one

if (testStepName == "SendPayment"){

						def request=context.expand('${SendPayment#Response}')
						log.info(request)
					}

Any input is appreciated. Thanks

 

 

  • arunbharath 

    Here you go:

     

    Please follow comments inline

    /**
    * Tear down script of suite
    **/
    
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    def processStep = { 
    	log.info "Step name : ${it.name}"
    	log.info "Case name : ${it.testCase.name}"
    	log.info "Suite name : ${testSuite.name}"
    	log.info "Response :\n ${it.testRequest.responseContentAsString}"
    	//Write logic below to save the response data to file here
    }
    
    testSuite.testCaseList.collect { kase ->
    	kase.testStepList.collect {
    		switch(it) {
    			//Process only REST requests; add additional cases as needed
    			case {it instanceof RestTestRequestStep}:
    				processStep it
    				break
    			default:
    				break
    		}
    	}
    }

    If you don't want to have the above script for each test suite or project, then you can use events, "TestRunListener.afterStepand have relevant logic to do the same. 

9 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    arunbharath 

    Here you go:

     

    Please follow comments inline

    /**
    * Tear down script of suite
    **/
    
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    def processStep = { 
    	log.info "Step name : ${it.name}"
    	log.info "Case name : ${it.testCase.name}"
    	log.info "Suite name : ${testSuite.name}"
    	log.info "Response :\n ${it.testRequest.responseContentAsString}"
    	//Write logic below to save the response data to file here
    }
    
    testSuite.testCaseList.collect { kase ->
    	kase.testStepList.collect {
    		switch(it) {
    			//Process only REST requests; add additional cases as needed
    			case {it instanceof RestTestRequestStep}:
    				processStep it
    				break
    			default:
    				break
    		}
    	}
    }

    If you don't want to have the above script for each test suite or project, then you can use events, "TestRunListener.afterStepand have relevant logic to do the same. 

    • arunbharath's avatar
      arunbharath
      Contributor

      nmrao  Thanks. It is working like a gem. I have one more question. How can we extract any specific datafield field value from the test-step Json api response?

      • nmrao's avatar
        nmrao
        Champion Level 3
        Nothing special, write logic to extract the required data. You can find samples in the forum or online search or from my GitHub.com/nmrao

        By the way you posted a question earlier related the same I guess. If so that can closed too.
  • nmrao's avatar
    nmrao
    Champion Level 3

    Appreciate if you can let us know what is the use case?

     

    "Right now I'm able to iterate the test cases and test steps but I could get the test step response.." - did not understand the issue. Did you miss something?

    • nmrao's avatar
      nmrao
      Champion Level 3
      And what are different type of test steps for which you need response?
      • arunbharath's avatar
        arunbharath
        Contributor

        Sorry my bad. Typo on the last message 

         

        Use Case:

        =========

        1) Let say I have a Test suite which has multiple testcases and each test case has multiple test steps. I want to iterate each test cases and test steps and get API response of test step based on the test-step name (using if-loop). after getting all the respective test-step response, I need to save those response in the file.

         

        2) Currently I'm having a script to iterate test-cases and test-steps, I need script to recive test-step response.