Forum Discussion

pankajmalinda's avatar
Occasional Contributor
6 years ago

Saving request and response

  I want to save request and response of all the tests(Failed/Passed) from my Automation test suite. The folder location should be like ProjectName-->TestSuiteName(Multiple folders for multi...
  • richie's avatar
    6 years ago

    Hi pankajmalinda


    There's a groovy event handler that does this quite nicely - the following script will record the request and response for each test step as well as the pass/fail result for every test step, in every test case, in every test suite in a project.


    The event handler is 'TestRunListener.AfterStep'


    The script is as below:  

    def pName = //get project name
    def pDate = new Date().format( 'yyyyMMdd' )//get current date
    def sDate = pDate.toString()//convert date to string
    def pTestSuite = TestSuite name
    def pTestCase = TestCase name
    def filePath = 'C:/SoapUI Projects/TS0.1/TestEvidence/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose the folder path
    File file = new File(filePath)
    if (!file.exists()) file.mkdirs()//create the destination folder
    fos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', true)
    pw = new PrintWriter( fos )
    testStepResult.writeTo( pw )


    I think this is brilliant - can't claim it was my code - I found it somewhere on - but it records everything!


    I use it as a way to capture my test evidence


    Hope this helps,