Unable to save TestSuite Response Result in SOAP UI

£可爱£侵袭症+ 提交于 2019-12-01 14:02:30

To save all response from a testSuite you can add a tearDown script which is executed at the end of testSuite execution. This groovy script loops over each testCase in the testSuite saving to disk each testStep response:

// path for the testSuite
def folderPath =  'C:/temp/' + 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 ->

        // to avoid problems with testSteps which not has response value (such as groovy script)
        def response = testStep.getProperty('Response')?.getValue()
        if(response){
            // define a file 
            def file = new File(folderPathSuite + testStepName + '_response.xml')
            // get the response and write to file
            file.write(response)
        }
    }
}

The tearDown script tab in testSuite panel: `

All response in one file

If instead, as you commnet you want all responses in one file you can do the same in tearDown script but using this code:

// create file to write all responses
def allResponses =  new File('C:/temp/' + testSuite.name + '_' + "AllResponses.xml")
def ls = System.getProperty("line.separator")
// for each testCase
testSuite.testCases.each { testCaseName, testCase ->

    allResponses << "TESTCASE: ${testCaseName}${ls}"

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

        allResponses << "TESTSTEP: ${testStepName}${ls}"
        // to avoid problems with testSteps which not has response value (such as groovy script)
        def response = testStep.getProperty('Response')?.getValue()
        if(response){
        // save the response to file
            allResponses << response + ls
        }
        allResponses << "END TESTSTEP: ${testStepName}${ls}"
    }

    allResponses << "END TESTCASE: ${testCaseName}${ls}"
}

If as you comment you want all this data in a .xls column, you need some external libraries to work with .xlsas for example Apache POI. IMO that is too much tricky to do so in your test.

If you want to do it anyway, take the Apache POI jars and copy it on SOAPUI/bin/ext folder, then restart SOAPUI in order to load the libraries. Now groovy script on your SOAPUI are ready to work with .xls using Apache POI classes. Here is a little example to start with groovy and Apache POI.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!