SOAPUI开源版本不提供导出报告功能,不过可以简单定制一番?..
看了两小时官网的文档,发现确实可行,且成本不高,虽然可能没有Pro版本的报告浑然一体不过勉强凑合了。
SoapUI的脚本语言是Groovy,这是啥?没听过,google之,原来如此这般...好吧。
第一步,收集执行的各种情况,生成一个xml报告,方便其他集成和后续改造,搞成一个HTML?
import com.eviware.soapui.SoapUI //log.info runner.getId() def sw = new StringWriter() def xml = new groovy.xml.MarkupBuilder(sw) //xml//根节点,加个版本号 xml.Report(type:"SoapUI",version:SoapUI.SOAPUI_VERSION ){//定义几个变量用来统计后续的成功总数和失败总数,警告总数 passedcount=0 failedcount=0 warningscount=0//遍历project的结果,得到suite结果 runner.getResults().each{tsuite -> //log.info tsuite.status passed=0 failed=0 warnings=0//遍历suite结果返回的成功状态,记录成功数,失败数... tsuite.getResults().status.each{ //log.info it if(it.toString()=="FINISHED"){ passed=passed+1 } else if(it.toString()=="FAILED"){ failed=failed+1 } else if(it.toString()=="WARNING"){ warnings=warnings+1 } } //log.info tsuite.getResults().status//加入一个suite子节点,带上name.status,runtime等等属性 TestSuite(name:tsuite.testSuite.getName(),status:tsuite.getStatus(),runtime:tsuite.getTimeTaken()/1000,stime:tsuite.getStartTime(),passed:passed,failed:failed){ tsuite.getResults().each{tcase -> passed=0 failed=0 warnings=0 tcase.getResults().status.each{ //log.info it if(it.toString()=="OK"){ passed=passed+1 passedcount=passedcount+1 } else if(it.toString()=="FAILED"){ failed=failed+1 failedcount=failedcount+1 } else if(it.toString()=="WARNING"){ warnings=warnings+1 warningscount=warningscount+1 } }//加入TestCase节点 TestCase(name:tcase.testCase.getName(),status:tcase.getStatus(),runtime:tcase.getTimeTaken()/1000,stime:tcase.getStartTime(),passed:passed,failed:failed,warnings:warnings){ tcase.getResults().each{tstep -> TestStep(name:tstep.testStep.getName(),status:tstep.getStatus(),runtime:tstep.getTimeTaken()/1000){ tstep.getMessages().each{message -> Message(message.toString()) } RequestHeaders(tstep.getRequestHeaders() ) } //log.info tstep.getResults() } } } } //} } //总览情况 Summary(name:project.name,sTime:project.getPropertyValue("stime"), etime:new Date().format(‘yyyy-MM-dd HH:mm:ss‘),status:runner.getStatus(), runtime:runner.getTimeTaken()/1000,passed:passedcount,failed:failedcount,warnings:warningscount) } log.info sw//输出到文件 new File("/Users/zhangminjie/SOAPUIReport.xml").write(sw.toString())
一气呵成,写完。然后发现冲动了,Groovy有几种生成XML的方式,我这是似乎使用了不是那么合适的方法,没关系,稍后修改。
不得不说Groovy处理xml非常很方便。
主要的几页文档:
http://www.soapui.org/apidocs/com/eviware/soapui/model/testsuite/TestStepResult.html
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
http://www.soapui.org/apidocs/com/eviware/soapui/model/testsuite/TestRunner.html
http://www.soapui.org/apidocs/index.html
时间: 2024-10-14 02:18:01