Forum Discussion

escupau's avatar
11 years ago

Handling a SOAP Fault

Hi folks, before i start i would like to apologize for my bad English :-).

Now to the topic: is there a possibility in a SoapUI TestRunListener to recognize whether the TestStepResult in the afterStep method contains any SOAP Fault? I've considered to use the NotSoapFaultAssertion adding it to my TestStep before it is executed. But if i do so, the runner just quits after the Assertion fails. I would like to do something like this:

public void afterStep(TestCaseRunner runner, TestCaseRunContext context, TestStepResult stepResult) {
//pseudo code
if(stepResult.containsSoapFalt()){
//do something special, for example
runner.gotoStep(32);
} else {
runner.gotoStep(18);
}
}

I would like to have a chance to handle any SOAP fault AND to let my runner continue however.

Thanks for Help.
  • nmrao's avatar
    nmrao
    Champion Level 3
    You may check for below condition

    if ( (context.httpResponse.responseContent.contains(':Fault')) || (context.httpResponse.responseContent.contains('<Fault')) ) {
    //Your stuff goes here
    }


    By the way, check if you might be interested in this library
    https://github.com/nmrao/soapuiExtensions
  • nmrao's avatar
    nmrao
    Champion Level 3
    Also there is another way:


    import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils
    import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion
    import static com.eviware.soapui.impl.wsdl.support.soap.SoapUtils.isSoapFault

    public void afterStep(TestCaseRunner runner, TestCaseRunContext context, TestStepResult stepResult) {
    def content = context.httpResponse.responseContent
    def soapVersion = SoapVersion.Soap11 //if 1.1, otherwise SoapVersion.Soap12
    if (isSoapFault(content,soapVersion)) {
    //your stuff goes here if response contains soap fault
    } else {
    //alternative stuff goes here
    }
    }