码迷,mamicode.com
首页 > 其他好文 > 详细

SOAPUI开源版简单定制报告2

时间:2015-01-10 22:17:23      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

稍微修改下实现,使用StreamingMarkupBuilder方法.

生成的xml的排版虽然没有了,不过不在意了,反正最终也不是直接读这玩意


import com.eviware.soapui.SoapUI
//log.info runner.getId()
//def sw = new StringWriter()
//def xml = new groovy.xml.MarkupBuilder(sw)
def builder = new groovy.xml.StreamingMarkupBuilder()
builder.encoding="UTF-8"
def Report = {
//xml
    mkp.xmlDeclaration()
    Report(type:"SoapUI",version:SoapUI.SOAPUI_VERSION ){
      passedcount=0
    failedcount=0
      warningscount=0
      runner.getResults().each{tsuite ->
      //log.info tsuite.status
      passed=0
      failed=0
      warnings=0
    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
      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(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(){
                      mkp.yieldUnescaped "<![CDATA[${message.toString()}]]>"
                      }
                  }
            RequestHeaders(){
                //
                mkp.yieldUnescaped "<![CDATA[${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

def writer = new FileWriter("/Users/zhangminjie/${project.name}-${new Date().format(‘yyMMddHHmmss‘)}.xml")
writer << builder.bind(Report)
//new File("/Users/zhangminjie/SOAPUIReport.xml").write(sw.toString())  

 

SOAPUI开源版简单定制报告2

标签:

原文地址:http://www.cnblogs.com/zhangminjie/p/4215640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!