我们可以使用SOAPUI保存TestSuite中测试步骤的所有SOAP响应吗?
我尝试通过DATA导出保存所有响应,但它只显示了总结结果,例如有多少测试用例通过/失败。但是我想保存TestSuite的所有请求的响应结果。
答案 0 :(得分:2)
要保存testSuite
的所有响应,您可以添加在tearDown script
执行结束时执行的testSuite
。这个groovy脚本遍历testCase
中的每个testSuite
,将每个testStep响应保存到磁盘:
// 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)
}
}
}
tearDown script
面板中的testSuite
标签:“
相反,如果您想要通信,您希望所有回复都在一个文件中,您可以在tearDown script
中使用此代码执行相同操作:
// 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}"
}
如果您在.xls
列中评论想要所有这些数据,则需要一些外部库来处理.xls
,例如Apache POI。 IMO在你的测试中太难了。
如果您还想这样做,请将Apache POI jar并将其复制到SOAPUI/bin/ext
文件夹中,然后重新启动SOAPUI以加载库。现在,您的SOAPUI上的groovy script
已准备好使用Apache POI类与.xls
一起使用。这是一个以groovy and Apache POI开头的小例子。