fa
7 years agoOccasional Contributor
XmlSlurper/XmlParser to store data from HTML content
Hello,
I am a new user of SoapUI community version (5.0.0).
I need to store the action value from the (HTML) response (below):
<html> <head> <meta content="HTML Tidy for Java (vers. 26 sept. 2004), see www.w3.org" name="generator"/> <title>201 Created</title> </head> <body> <h1>TGT Created</h1> <form method="post" action="URI"> Service: <input value="" name="service" type="text"/> <br/> <input value="Submit" type="submit"/> </form> </body> </html>
I am trying to use Groovy to finally get this value (through XmlSlurper or XmlParser) using the following declarations (to parse the context) through Script assertion (on the same step):
import groovy.util.XmlSlurper; def response = context.expand( '${Login#Response}' ).toString(); def slurper = new XmlSlurper(); def xmldata = slurper.parseText response;
.. but i get "Premature end of file".
Could someone provide some information about this problem?
Thank you in advance
SoapUI has already converted HTML to standard XML format (with closed tags). By changing the script to responseContentAsXml you could get the action value
import groovy.util.XmlSlurper; def response = messageExchange.responseContentAsXml; def slurper = new XmlSlurper(); def xmldata = slurper.parseText response;
def action = xmldata.body.form.@action
log.info action