cancel
Showing results for 
Search instead for 
Did you mean: 

JSON response Contains HTML content , Assert on the content

SOLVED
Highlighted
Contributor

JSON response Contains HTML content , Assert on the content

subhaD_0-1601394923079.png

 

I am trying to parse a response JSON tag containing HTML content.

I have to write groovy script to assert on the value in response with whats in html.

I am failing parsing that, code here 

import groovy.util.XmlSlurper;

def response = context.expand( '${REST Request#Response#$[\'data\'][\'meta\'][\'fields\'][0][\'message\']}' ).toString();

def slurper = new XmlSlurper();
def xmldata = slurper.parseText response;

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: JSON response Contains HTML content , Assert on the content

Hey @subhaD,

You can actually do whst you need without using any groovy script at all...the native functionality will do what you need.
If you search the help for handling CDATA from a response from the readyapi! help, you cant use the same property inside a property method to do what you need.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

4 REPLIES 4
Highlighted
Community Leader

Re: JSON response Contains HTML content , Assert on the content

@subhaD : You can get help from below link's solution

 

https://community.smartbear.com/t5/SoapUI-Pro/ReadyAPI-download-a-textfile-from-a-URL-with-groovyscr...

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: JSON response Contains HTML content , Assert on the content

Hi,

 

A couple of points.  An example response would be good to help us understand what you are facing.

 

Also, you talk about HTML in a JSON tag, but you're trying to tease out the details using XML Slurper.  

 

If it's XML you want to work with, maybe try :-

def response = context.expand( '${REST Request#ResponseAsXml#$[\'data\'][\'meta\'][\'fields\'][0][\'message\']}' ).toString();
Highlighted
Contributor

Re: JSON response Contains HTML content , Assert on the content

I have a html report displayed in message tag like below,

I was hoping to parse it and be able to go traverse and assert on that like //td[4] .contains "James" 

Hoping to understand of there is any way to do that

"message" : "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>  <HTML  xmlns='http://www.w3.org/1999/xhtml' >  <META http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>   <HEAD> <style type='text/css'> .BODY { FONT-FAMILY: Arial; FONT-SIZE: 12px; } .TABLE { FONT-FAMILY: Arial; FONT-SIZE: 12px; text-align : center; vertical-align : middle; } .TD { FONT-FAMILY: Arial; FONT-SIZE: 12px; } .tdpurple { Background-COLOR: #330066; FONT-FAMILY: Arial; FONT-SIZE: 11px; TEXT-DECORATION: none; } .copyright { FONT-FAMILY: Arial; FONT-SIZE: 10px; vertical-align : bottom; text-align : center; } .nav_blackbar { COLOR: #FFFFFF; FONT-FAMILY:  Arial; FONT-SIZE: 11px; TEXT-DECORATION: none; } A.nav_blackbar:hover { COLOR: #ff9933; FONT-FAMILY:  Arial; FONT-SIZE: 11px; TEXT-DECORATION: none; } .nav_pinkbar { COLOR: #330066; FONT-FAMILY:  Arial; FONT-SIZE: 11px; TEXT-DECORATION: none; } A.nav_pinkbar:hover { COLOR: #ff9933; FONT-FAMILY:  Arial; FONT-SIZE: 11px; TEXT-DECORATION: none; } .nav_greenbar { COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; TEXT-DECORATION: none; } .white { COLOR: #FFFFFF; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 10px; TEXT-DECORATION: none; } .nav_footer { COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; TEXT-DECORATION: none; } A.nav_footer:hover { COLOR: #99cc00; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 11px; TEXT-DECORATION: none; } .nav_leftside { COLOR: #0000ff; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 12px; TEXT-DECORATION: underline; } A.nav_leftside:hover { COLOR: #ff0000; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 12px; } .current_date { FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 9px; text-align : right; } .content_group_name { FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 12px; FONT-WEIGHT: bold; } .content_headergroup_name { FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 16px; FONT-WEIGHT: bold; } .backtotop_link { FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 9px; } .bold { font-weight:bold; } .gray{ color:gray; font-weight:bold; } INPUT.button1 { font-weight: normal; text-align: center; width:110px; } INPUT.button2 { font-weight: normal; text-align: center; width:200px; } INPUT.button3 { font-weight: normal; text-align: center; width:220px; } INPUT.text30 { width: 30px; } INPUT.text40 { width: 40px; } INPUT.text50 { width: 50px; } INPUT.text110 { width: 110px; } INPUT.text200 { width: 200px; } INPUT.text300 { width: 300px; } .red{ color:red; } .small { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-variant: normal; text-align: center; } .smallbold { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-weight: bold; text-align: center; } .smaller { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 8.0pt; font-variant: normal; text-align: center; } TABLE.gray{ background-color: #E5E5E5; } TD, .TableData {color: black; font-family:Arial, Helvetica, sans-serif; font-size: 10.0pt; font-variant: normal; font-weight: normal; text-align: left; } TD.small{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-variant: normal; text-align: center; } TD.smaller{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 8.0pt; font-variant: normal; text-align: center; } TD.smallest{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 7.0pt; font-variant: normal; text-align: center; } TH{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 10.0pt; font-variant: normal; font-weight: bold; text-align: center; } TH.small { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-variant: normal; font-weight: bold; text-align: center; } TH.smaller { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 8.0pt; font-variant: normal; font-weight: bold; text-align: center; } TH.smallest { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 7.0pt; font-variant: normal; font-weight: bold; text-align: center; } .rightalign{ text-align: right; } .lalign{ text-align: left; } .centrealign{ text-align: center; } .href{ COLOR: #330066; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px; TEXT-DECORATION: none; } A.href:hover{ COLOR: Red; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 12px; TEXT-DECORATION: none; } .greenback{ background : #99CC00; } .blackback{ background : #000000; } .darkpurple{ background : #330066; } .PageHeader{ FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 19px; FONT-WEIGHT: bold; } .smallleft{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-variant: normal; text-align: left; } .smallboldleft{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9.0pt; font-variant: normal; font-weight: bold; text-align: left; } .smallerboldleft { color: black; font-family:Arial, Helvetica, sans-serif; font-size: 8.0pt; font-variant: normal; font-weight: bold; text-align: left; } .smallerleft{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 9pt; font-variant: normal; text-align: left; } .subheading{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 10.0pt; font-variant: normal; font-weight: bold; text-align: left; } .redsubheading{ color: red; font-family:Arial, Helvetica, sans-serif; font-size: 12.0pt; font-variant: normal; font-weight: bold; text-align: left; } .errorname{ text-align : center; text-decoration : none; font-size : 18px; color : Red; } .chexheading{ color: black; font-family:Arial, Helvetica, sans-serif; font-size: 10.0pt; font-variant: normal; text-align: right; } .errordesc{ text-align : center; text-decoration : none; font-size : 14px; color : Red; } .whiteback { background-color: #FFFFFF; } .H1White {         font-size: .90em; font-family: Arial, Helvetica, sans-serif; color: #ffffff; font-weight: bold;         }         .H1Gray {         font-size: .90em; font-family: Arial, Helvetica, sans-serif; color: #cccccc; font-weight: bold;         } .textsecondary { FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; } </style> </HEAD> <br><table align='center' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr id='TOP'>&amp;</tr> <tr> <td class='subheading'>Consumer Information (As Entered)</td> <td>&amp;</td></tr> <tr><td bgcolor='#000000' height='1' colspan='2'></td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr> <td class='smallerboldleft' width='50%'>&amp;&amp;&amp;JAMES  MMAUVE</td> <td class='smallerboldleft' width='*%'>SSN/ITIN:&amp;666-06-6294</td> </tr> <tr><td class='smallerboldleft' width='50%'>&amp;&amp;&amp;1295 HEXAGON RD</td> <td class='smallerboldleft' width='*%'>DOB:&amp;12/20/1956</td> </tr> <tr> <td class='smallerboldleft'>&amp;&amp;&amp;OZARK,&amp;AL&amp;36360</td> <td class='smallerboldleft' width='*%'>&amp;</td> </tr> <tr> <td class='smallerboldleft' width='50%'>&amp;&amp;&amp;</td> <td class='smallerboldleft' width='*%'>&amp;</td> </tr> <tr> <td colspan='2'>&amp;</td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'><tr>        <td class='smallerboldleft' width='10%' nowrap>&amp;&amp;&amp;Home Phone:&amp;</td>        <td class='smallerboldleft'  width='*' align='left'>(334)445-5678</td> <td width='*'>&amp;</td></tr><tr> <td colspan='2'>&amp;</td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'><tr> <td class='smallerboldleft' width='13%' nowrap>&amp;&amp;&amp;Country:  </td> <td class='smallerboldleft'>&amp;&amp;United States</td></tr></table> <table align='center' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr>&amp;</tr> <tr> <td class='subheading'>Account Actions </td> <td>&amp;</td></tr> <tr><td bgcolor='#000000' height='1' colspan='2'></td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr><td width='10%' class='smallerboldleft'>&amp;&amp;&amp;Action:</td> <td width='*' class='smallerleft'>ACCEPT</td> <td  class='smallerleft'>&amp;</td></tr> <tr><td colspan='3'>&amp;</td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr><td width='25%' class='smallerboldleft'>&amp;&amp;&amp;Recommended Actions:</td> <td width='*' class='smallerleft'>OPEN ACCOUNT                  </td></tr> </table> <p></p> <p></p> <p></p> <table align='center' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr>&amp;</tr> <tr> <td class='subheading'>QualiFile&#0174; Detail</td> <td>&amp;</td></tr> <tr><td bgcolor='#000000' height='1' colspan='2'></td></tr> </table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'>  <tr ><td width='45%'>&amp;</td><td width='10%' class='smallerboldleft'><u>Code</u></td><td width='45%' class='smallerboldleft'><u>Text</u></td></tr></table> <table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr ><td width='20%' class='smallerboldleft'>&amp;&amp;&amp;QualiFile Score:</td><td width='10%' class='smallerleft'>9999</td><td width='13%' class='smallerboldleft'>Reasons:</td><td valign='top' width='10%' class='smallerleft'> Z3</td><td valign='top' width='45%' class='smallerleft'>INSUFFICIENT DATA FOUND                                     </td></tr> </table><table align='center' class='gray' width='98%' border='0' cellpadding='0' cellspacing='0'> <tr ><td colspan='2'>&amp;</td></tr>   <tr >  <td align='left' colspan='2'> </td></tr><tr >  <td align='left'></td>  </tr></table> <p></p><table cellspacing='0' cellpadding='0' border='1' BORDERCOLOR='gray' width='98%' align='center'> <tr><td class='subheading' width='30%'>&amp;Non FCRA</td></tr> <tr><td height='1' bgcolor='#000000'></td></tr> <tr><td><table cellspacing='0' cellpadding='0' border='0' width='100%' align='center'> <tr><td><tab>.......</HTML>

Highlighted
Community Hero

Re: JSON response Contains HTML content , Assert on the content

Hey @subhaD,

You can actually do whst you need without using any groovy script at all...the native functionality will do what you need.
If you search the help for handling CDATA from a response from the readyapi! help, you cant use the same property inside a property method to do what you need.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors