Forum Discussion

craigcanderson's avatar
craigcanderson
Contributor
15 years ago

XPath Match Assertion Failing

Background
I'm using soapUI Pro 3.6.1. When my test case executes the XPath Match assertion always has a status of "FAILED". If I double click on the assertion to open it up, and press the "Test" button, I get a message box titled "Success" with the message "Response matches content for [declare namespace...]" and the status changes to "SUCCESS". I'm allowing wildcard characters ('*') to be used. The response is XML, with one node containing EDI information that has been replaced with the wildcard character '*' (<EDIData>*</EDIData>) and another node containing XML "wrapped" within a CDATA tag (<XMLData><![CDATA[[xml_data]]></XMLData>).

For the node "wrapped" in a CDATA tag, I've created an event handler (SubmitListener.afterSubmit) with the associated code of:
if( submit.response == null )
return

def content = submit.response.responseContent
content = content.replaceAll("<!\\[CDATA\\[", "")
content = content.replaceAll("]]>", "")

log.info(content)

submit.response.responseContent = content

to "strip" off the "<![CDATA[" and "]]>" string pieces from the response XML associated with the XMLData node. As part of the XPath Match assertion for this node, the wildcard character '*' is being used for date and time values that will change from execution to execution.

Questions

  • Why do I have to open the assertion each time and press the "Test" button to get the assertion to pass?

  • Is there something that I have to configure so that automatically upon the completion of test case execution the functionality associated with the "Test" button is executed?


I've never had this problem in the past using the XPath Match assertion.

3 Replies

  • Hello,


    Well. there is an issue with assertions and this event. Instead try adding RequestFilter.afterRequest event and add script like this:

    if( request.response == null )
    return

    def content = context.httpResponse.responseContent
    content = com.eviware.soapui.support.xml.XmlUtils.prettyPrintXml( content )
    // manipulate content
    content = content.replaceAll( "444", "555" )
    log.info( content )

    context.httpResponse.responseContent = content


    This will do what you need.

    Hope this helps,
    robert
  • Awesome's avatar
    Awesome
    Frequent Contributor
    hi

    i'm having the exact same issue: when i run my complete testcase my teststep assertions fail; however, they do pass if i run them individually. i tried both events (SubmitListener.afterSubmit, RequestFilter.afterRequest) but i still have the same problem (both events are correctly parsing out the CDATA from my xml though...)