SOAPUI Open source version simple custom report 3

Source: Internet
Author: User
Tags cdata soapui

Importcom.eviware.soapui.SoapUIdef Getreporttoxml () {def builder=NewGroovy.xml.StreamingMarkupBuilder () builder.encoding= "UTF-8"def Report={mkp.xmldeclaration () report (Type:"SoapUI", Version:SoapUI.SOAPUI_VERSION) {Passedtotal=0Failedtotal=0Warningstotal=0Testcasetotal=0runner.getresults (). Each{tsuite-passed=0failed=0Warnings=0tsuite.getresults (). status.each{if(it.tostring () = = "Finished") {passed=passed+1              }        Else if(it.tostring () = = "FAILED") {failed=failed+1            }        Else if(it.tostring () = = "WARNING") {Warnings=warnings+1}} testcasetotal=testcasetotal+tsuite.getresults (). Size ()//log.info tsuite.getresults (). Size ()TestSuite (Name:tsuite.testSuite.getName (), Total:tsuite.getResults (). Size (), Status:tsuite.getStatus (), Runtime: Tsuite.gettimetaken ()/1000, Stime:tsuite.getStartTime (), passed:passed,failed:failed) {tsuite.getresults (). Each{tcase-passed=0failed=0Warnings=0tcase.getresults (). status.each{if(it.tostring () = = "OK") {passed=passed+1Passedtotal=passedtotal+1              }        Else if(it.tostring () = = "FAILED") {failed=failed+1Failedtotal=failedtotal+1            }        Else if(it.tostring () = = "WARNING") {Warnings=warnings+1Warningstotal=warningstotal+1}} TestCase (Name:tcase.testCase.getName (), Status:tcase.getStatus (), Runtime:tcase.getTimeTak En ()/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 ()}]]> "}}}}}} Summary (Name:project.name,total:testcasetotal,stim E:project.getpropertyvalue ("Stime"), ETime:NewDate (). Format (' Yyyy-mm-dd HH:mm:ss '), Status:runner.getStatus (), Runtime:runner.getTimeTaken ()/1000, Passed:passedtotal,failed:failedtotal,warnings:warningstotal)}}//def writer = new FileWriter ("${getreportpath ()}${new Date (). Format (' Yymmddhhmmss ')}.xml")builder.bind (report)//writer << XML}def getreportpath (filename) {Matcher= Project.path.toString () =~/.*\//File f =NewFile ("${matcher[0]}report/${project.name}/") F.mkdirs ()NewFile ("${matcher[0]}report/${project.name}/${filename}")}def GetXML=Getreporttoxml ()//Log.info GetXMLdef reportxml =NewXmlparser (). ParseText (Getxml.tostring ())//log.info reportxml["Summary"][0].attribute ("name")def SW =NewStringWriter () def HTML=NewGroovy.xml.MarkupBuilder (SW) def Htmlstyle=" "table.gridtable {font-family:verdana,arial,sans-serif; Font-size:11px; color:#333333; Border-width:1px; Border-color: #666666; Border-Collapse:collapse; } table.gridtable th {border-width:1px;            padding:8px; Border-Style:solid; Border-color: #666666; Background-color: #dedede; } table.gridtable td {Border-width:1px;            padding:8px; Border-Style:solid; Border-color: #666666; Background-color: #ffffff;            } p.request{color:red; Font-Size:medium; }" "html.html{head{Meta ("Http-equiv": "Content-type", Content: "Text/html;charset=utf-8") title ("Report-${project.name}") style (type:"Text/css", Htmlstyle)} body{Div ("style": "Width:80%;margin-left:auto;margin-right:auto;", Align: "center") {h1 (align:"Center", "${project.name} Execution Report") H3 (align:"Left", "Overview") Table (align:"Center", "class": "Gridtable", Width: "100%") {tr () {th ("Start Time") th ("End Time") th ("Time-consuming (s)") th (Results) th (Total) th ("Number of successes") th ("Number of failures")                    //th ("Warning")} TR () {TD (Reportxml["Summary"][0].attribute ("Stime")) TD (Reportxml["Summary"][0].attribute ("ETime")) TD (Reportxml["Summary"][0].attribute ("Runtime")) TD (Reportxml["Summary"][0].attribute ("status")) TD (Reportxml["Summary"][0].attribute ("Total")) TD (Reportxml["Summary"][0].attribute ("passed")) TD (Reportxml["Summary"][0].attribute ("failed"))                    //TD (Reportxml["Summary"][0].attribute ("warnings"))}} h3 (align:"Left", "Test set") Table (align:"Center", "class": "Gridtable", Width: "100%") {tr () {th (Name) th ("Time-consuming (s)") th (Results) th (Total) th ("Number of successes") th ("Number of failures")} reportxml.testsuite.each{tsuite-tr () {//Log.info TsuiteTD (Tsuite.attribute ("name")) TD (Tsuite.attribute ("Runtime")) TD (Tsuite.attribute ("Status")) TD (Tsuite.attribute ("Total")) TD (Tsuite.attribute ("Passed")) TD (Tsuite.attribute ("Failed"))}}} reportxml.testsuite.each{ Tsuite-h4 (align:"Left", Tsuite.attribute ("name") Table (align:"Center", "class": "Gridtable", Width: "100%") {tr () {th (Name) th ("Time-consuming (s)") th (Results)} tsuite. Testcase.each{tcase-TR () {TD (Tcase.attribute ("Name")) TD (Tcase.attribute ("Runtime")) TD (Tcase.attribute ("Status"))                    }                if(Tcase.attribute ("status"). ToString () = = "FAILED") {TR () {TD (Colspan:"3") {tcase. Teststep.each{tstep-if(Tstep.attribute ("status") = = "FAILED") {p ("Class": "Request", "Name: ${tstep.attribute (")} Time: ${tstep.attribute ("Runtime")} ") Tstep. Message.each{message-P (Message.Text ())}}                }                         }                    }                }                }                                } P (align:"Right") {A (href: "Javascript:scroll (0,0)", "back to Top")}            }}}}def reporttime=NewDate (). Format (' Yymmddhhmmss ') Getreportpath ("${reporttime}.html"). Write (Sw.tostring ()) def writer=NewFileWriter (Getreportpath ("${reporttime}.xml"))//log.info sw.tostring ()Writer.write (GetXML)

SOAPUI Open source version simple custom report 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.