DouglasY
7 years agoOccasional Contributor
How do I test for non-existence of an XML element while avoiding error: Unexpected element: CDATA
// The following sample is based on advice given on SmartBear community about how to check for the non-existence of an xml element
// https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-check-non-existence-of-a-xml-element/m-p/37511/highlight/true#M15180
def testStepName = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()
def expectNull = context.expand( '${'+testStepName+'#Request//*:nonExistentField}' )
assert expectNull.isEmpty()
// The assertion works as expected; however, the code generates an error when expanding the Xpath
// ERROR:An error occurred [error: Unexpected element: CDATA], see error log for details
// How do I test for non-existence of an XML node without generating an ERROR in SoapUI?