Forum Discussion

Sirisha2020's avatar
Sirisha2020
Contributor
4 years ago

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

    • ChrisA's avatar
      ChrisA
      Contributor

      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)
              }
      • Sirisha2020's avatar
        Sirisha2020
        Contributor

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