cancel
Showing results for 
Search instead for 
Did you mean: 

I want to save the request and response on test suite level

Occasional Contributor

I want to save the request and response on test suite level

Hi,

I have requirement to save the request and response on test suite level. Also we have to save the request and response in different folders costumer and sales rep(i.e. Filtering the test case response files based on test case name and saving them in respective folders). I am working on the below mentioned script with which i am not getting response files for the test cases that are there in test suite.

code ;

def folderPath = "C:/Users/SS/Desktop/proj/" + testSuite.name + '_' + System.currentTimeMillis() + File.separator
new File(folderPath).mkdirs()

// for each testCase in the testSuite
testSuite.testCases.each { testCaseName, testCase ->

// path for this testCase
def folderPathSuite = folderPath + testCaseName + File.separator
new File(folderPathSuite).mkdir()

// for each testStep
testCase.testSteps.each { testStepName, testStep ->


def response = testStep.getProperty('Response').getValue()
if(response){
// define a file
def file = new File(folderPathSuite + testStepName + '_response.json')
// get the response and write to file
file.write(response)
}
}
}

Thanks in advance.

18 REPLIES 18
Community Manager

Re: I want to save the request and response on test suite level

Thanks for the query!

 

Let's asl the Community to help, perhaps some folks faced similar use cases.

 

@PrathapR @ChrisA @HimanshuTayal @msiadak @avidCoder 

any thoughts?🙂


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Contributor

Re: I want to save the request and response on test suite level

Hi,

 

Before looking at writing requests and responses, are you sure your script is correctly iterating over the test steps and 'picking' up the step name?

 

Try using log.info to check.  E.g. in your loop....

 

testSuite.testCases.each { testCaseName, testCase ->

    log.info("TestCaseName " + testCaseName);

    // path for this testCase
    def folderPathSuite = folderPath + testCaseName + File.separator;
    new File(folderPathSuite).mkdir();
    // for each testStep
    testCase.testSteps.each { testStepName, testStep ->

        log.info("TestStepName " + testStepName);
        def response = testStep.getProperty('Response').getValue();

        log.info(response);

        if(response){
            // define a file
           def file = new File(folderPathSuite + testStepName + '_response.json')
           // get the response and write to file
           file.write(response)
        }
Occasional Contributor

Re: I want to save the request and response on test suite level

The below code is not working and it is giving some errors

Contributor

Re: I want to save the request and response on test suite level

Hi,

 

It will throw errors as it is incomplete, for example the loop is not closed.

 

It's purely an example excerpt from your original code just to suggest where you might want to try some logging to see if the loop is working as intended.

Occasional Contributor

Re: I want to save the request and response on test suite level

Hi Chris,

I closed the loop but still i am getting some other errors which i am not aware of them. We are trying to find is there a way to save request and response in REST API services on test suite level.  I am in novice in groovy script.  

 

Thanks,

Contributor

Re: I want to save the request and response on test suite level

Hi,

 

Your groovy script is looking pretty good, keep going.

 

Would you like to post what you have currently?  It would be nice if you could tell us what the errors are and where in your code they occur.

 

 

Occasional Contributor

Re: I want to save the request and response on test suite level

Hi chris,

I am getting the below error when i am trying to run the below code in soapUI log ;

Fri Oct 23 10:03:55 EDT 2020:ERROR:An error occurred [No such property: testSuite for class: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner], see error log for details

 

Code:

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

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

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

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

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

def request=context.expand('${testStepName#Request}')
log.info(request)


}

log.info(testCaseName)
}

 

Contributor

Re: I want to save the request and response on test suite level

@Sirisha2020 

We have to navigate testep to testcase, testcase to testsuite then project. updated below code, please try and let us know, 

Code:

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

def testCaseName = testRunner.testCase.testSuite.getTestCaseAt(i).getName()

def testStepCount = testRunner.testCase.testSuite.getTestCaseAt(i).getTestStepCount()

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

def testStepName = testRunner.testCase.testSuite.getTestCaseAt(i).getTestStepAt(j).getName()
log.info(testStepName)

def request=context.expand('${V6GetPackageAttributeList#Request}')
log.info(request)


}

log.info(testCaseName)
}

Occasional Contributor

Re: I want to save the request and response on test suite level

Hi Redde,

Thanks for your reply. I gave try with the below code. I created a new test case at last and added a test step as a groovy script. During the execution using the test suite editor, groovy script also executed. But it is not retrieving all the test case details. It is leaving around 4 to 5 and displaying test step name, test case name. We are not getting request and response.

 

  • Fri Oct 23 12:36:25 EDT 2020:INFO:Test Step1
  • Fri Oct 23 12:36:25 EDT 2020:INFO: --NO Request
  • Fri Oct 23 12:36:25 EDT 2020:INFO: --NO Response
  •  
  • Fri Oct 23 12:36:25 EDT 2020:INFO:TestStep2
  • I have modified the code to display response also.
  • def res=context.expand('${V6GetPackageAttributeList#Response}')
  • log.info(res)
  • But it is not displaying the request as well as response.

Thanks.

  •  
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors