xml - Validate a webpage against its doctype (dtd) within a Canoo Webtest step using a Groovy script -


how can validate webpage against doctype (dtd) within canoo webtest step groovy?

actually know answer. took me while working, thought i'd share solution. it's webtest macro. can use sequential if like...

<macrodef name="verifyschema" description="validate current document against schema"> <sequential>     <groovy description="validate schema" >         import javax.xml.parsers.parserconfigurationexception         import javax.xml.parsers.saxparser         import javax.xml.parsers.saxparserfactory          import java.io.inputstreamreader           import org.xml.sax.errorhandler         import org.xml.sax.inputsource         import org.xml.sax.saxexception         import org.xml.sax.saxparseexception         import org.xml.sax.xmlreader          class myhandler implements org.xml.sax.errorhandler {             void warning(saxparseexception e) throws saxexception {                 println 'warning: ' + e.getmessage()             }              void error(saxparseexception e) throws saxexception {                 println 'error: ' + e.getmessage()                 throw e             }              void fatalerror(saxparseexception e) throws saxexception {                 println 'fatal: ' + e.getmessage()                 throw e             }         }               def factory = saxparserfactory.newinstance()             factory.setvalidating(true)             factory.setnamespaceaware(true)              def parser = factory.newsaxparser()             def reader = parser.getxmlreader()             reader.seterrorhandler(new myhandler())             def response = step.context.currentresponse.webresponse             reader.parse(new inputsource(new inputstreamreader(response.contentasstream,"utf-8")))     </groovy> </sequential> 

if want fail test on warnings too, add throw statement handler accordingly.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -