0
votes

I have a testSuite with lets say 5 cases, i run the cases from my testSuite.

In my tear down script I want to capture all request and response of all testcases all test testSteps.

Below is the code I have written in tearDown TestSuite, problem in context.expand is returning empty. I assume testCase context is require, or not sure where i am going wrong.

tc_list = testSuite.getTestCaseList()
tc_count = tc_list.size()
for(i=0;i<tc_list.size();i++){
    if(!tc_list[i].isDisabled()){

        ts_list =  tc_list[i].getTestStepList()

        for(j=0;j<ts_list.size();j++){
            req = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_RequestData.txt'
            res = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_ResponseData.txt'

            def request_expand = context.expand('${'+ts_list[j].getName()+'#Request}')
            log.info '${'+ts_list[j].getName()+'#Response}'+tc_list[i].getName()
               def response_expand = context.expand('${'+ts_list[j].getName()+'#Response}')
              log.info response_expand



             /* def req_file = new File(req)
               req_file.write(request_expand,"UTF-8")
               def res_file = new File(res)
               res_file.write(response_expand,"UTF-8") */



            }
        }


    }
2
Are you using open source edition? or Pro? Usually it captures request and response for the failed steps. Do you those irrespective of the result status? - Rao

2 Answers

0
votes

@Ragesh kr

Whenever any time in Soap ui or Ready API you need RawRequest or RawResponse

you can just replace Request with RawRequest and Response with RawResponse

i just did in your code and it worked

        def request_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("RawRequest")
        def response_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("RawResponse")

Some other examples to help everyone

When we just need request and response in soapui we can use below

enter image description here

When we just need RawRequest and RawResponse in soapui/ReadyaPI via groovy we can use below

 req=context.expand('${RequestStepName#RawRequest}')
 log.info req
 res=context.expand('${RequestStepName#RawResponse}')
 log.info res

enter image description here

0
votes

The Below code worked for me. But I am still trying to capture rawRequest and rawResponse, which is still not achieved

tc_list = testSuite.getTestCaseList()
tc_count = tc_list.size()
for(i=0;i<tc_list.size();i++){
    if(!tc_list[i].isDisabled()){

        ts_list =  tc_list[i].getTestStepList()

        for(j=0;j<ts_list.size();j++){

            req = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_RequestData.txt'
            res = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_ResponseData.txt'

            def request_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("Request")
            def response_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("Response")
            def req_file = new File(req)
            def res_file = new File(res)
            log.info testSuite.getTestCaseByName(tc_list[i].getName()).getName()+' '+testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getName()+' '+response_expand
            if(request_expand!=null && response_expand!=null){

                 log.info testSuite.getTestCaseByName(tc_list[i].getName()).getName()+' '+testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getName()+' '+response_expand

               req_file.write(request_expand,"UTF-8")

               res_file.write(response_expand,"UTF-8")
                }

            }
        }


    }