Forum Discussion

partyk1d24's avatar
partyk1d24
New Contributor
12 years ago

TestCase that Succeeds on Exception

Is there a way to write a TestCase that Succeed (instead of fails) on exception. Meaning if I get back a success response then it has failed.

Thanks!

4 Replies

  • cwlovell13's avatar
    cwlovell13
    Occasional Contributor
    I would think that using an XPath Assertion to look for the failure in the response should do the trick for you.
  • partyk1d24's avatar
    partyk1d24
    New Contributor
    Not great with XPath, anyway could you give an example? Would a Groovy script be just as easy? I would assume I would set fail on fault or whatever to no rt?
  • cwlovell13's avatar
    cwlovell13
    Occasional Contributor
    I don't know GROOVY sorry...

          
    <soap:Fault>
    <faultcode>soap:Server</faultcode>
    <faultstring>Server was unable to process request. ---> Format of the initialization string does not conform to specification starting at index 0.</faultstring>
    <detail/>
    </soap:Fault>


    So for example the above is an error I get when I do not use the correct connection string properties. I would setup a XPath assertion like this to look for the failure...


    XPath Expression:
    declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
    //soap:Fault

    XPath Result:
    <soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <faultcode>soap:Server</faultcode>
    <faultstring>Server was unable to process request. ---> Format of the initialization string does not conform to specification starting at index 0.</faultstring>
    <detail/>
    </soap:Fault>


    Basically the easiest way to do it is to create the TestCase and send a request that fails. Then Add Assertion, and use the Response to create your assertion. Then ever time that test case is run it will check for the failure, and if it doesn't fail in the same way or if it passes it will fail the test.

    Most of this can be done automatically by just click Add Assertion, picking XPath Match, then clicking on Declare, and Select from current. You can modify the declare so that you only look for a specific section of the response, then click 'Select from current' and it will import from the current response you have.