Forum Discussion

eeyoreeco's avatar
eeyoreeco
Occasional Contributor
11 years ago

Throw Exception on First Error And Stops

Hi All,

Please help me with this one. Usually when an Error (1st) is being encountered the validation of the other parameters stops.
Just like in my sample request and the fault string below. Is there any way so that all the parameter will be validated.
In this case I want to see that both "FromCurrency" and "ToCurrency" to be validated in just one run of request. Thanks for the help.



REQUEST:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>BBB</web:FromCurrency>
<web:ToCurrency>AAA</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>


FAULT STRING:
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (5, 50). ---> System.InvalidOperationException: Instance validation error: 'BBB' is not a valid value for Currency.

6 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    This is a server side issue. Essentially, your dev team would have to create this. The problem is, why? If it continues to parse a request that it knows is faulty than it is wasting processing speed. Which in turn costs more money.
  • eeyoreeco's avatar
    eeyoreeco
    Occasional Contributor
    PaulM wrote:
    This is a server side issue. Essentially, your dev team would have to create this. The problem is, why? If it continues to parse a request that it knows is faulty than it is wasting processing speed. Which in turn costs more money.


    Actually the reason why I'm asking this, so that in just one run of 'request' I will be able to verify all the validation for all parameters that are in the xml request. (for testing purposes - negative scenario)
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    eeyoreeco wrote:
    PaulM wrote:
    This is a server side issue. Essentially, your dev team would have to create this. The problem is, why? If it continues to parse a request that it knows is faulty than it is wasting processing speed. Which in turn costs more money.


    Actually the reason why I'm asking this, so that in just one run of 'request' I will be able to verify all the validation for all parameters that are in the xml request. (for testing purposes - negative scenario)



    Yes, I understand that this would make testing far easier but as I said, it would require development to change the code to continue parsing the data after invalid data is found on the server side. While this would be amazing for testing purposes in production this would be horrible since it will consume all of the standard resources that a failed example would consume.

    If you want development to make a change that will hinder production and cost your company FAR more money just to make testing easier. Instead of wanting that, why not set up a groovy script that will constantly replace a single node with a faulty parameter and then run the test case over and over again to verify the failures?
  • eeyoreeco's avatar
    eeyoreeco
    Occasional Contributor
    PaulM wrote:
    eeyoreeco wrote:
    PaulM wrote:
    This is a server side issue. Essentially, your dev team would have to create this. The problem is, why? If it continues to parse a request that it knows is faulty than it is wasting processing speed. Which in turn costs more money.


    Actually the reason why I'm asking this, so that in just one run of 'request' I will be able to verify all the validation for all parameters that are in the xml request. (for testing purposes - negative scenario)



    Yes, I understand that this would make testing far easier but as I said, it would require development to change the code to continue parsing the data after invalid data is found on the server side. While this would be amazing for testing purposes in production this would be horrible since it will consume all of the standard resources that a failed example would consume.

    If you want development to make a change that will hinder production and cost your company FAR more money just to make testing easier. Instead of wanting that, why not set up a groovy script that will constantly replace a single node with a faulty parameter and then run the test case over and over again to verify the failures?



    Thanks Paul!. would you be able to help me regarding of using a groovy script that will constantly replace a single node with a faulty parameter and then run the test case over and over again ?
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Sure thing, I will set up a quick example script that you should be able to use that will perform these actions.



    //Setting up variables here.
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

    //Change "testName" to the name of the test step you are wanting to perform this on
    def holder = groovyUtils.getXmlHolder("testName#Request");
    def xml = holder.getPrettyXml();


    //This regexp grabs all child nodes that have a variable. Note for some odd reason, it leaves the '?' in the request and it also will not make any changes to any null or empty child nodes. The idea here is to start with a valid request
    def regexp = ("<([^<>]+)>(.*?)</\\1>");

    def matcher = xml =~ regexp;

    //Change testName here again. It might be a better idea to set this as a property or variable in the script.
    def controlledStep = testRunner.testCase.getTestStepByName("testName");

    //This section iterates through each of the regex matches
    matcher.each {


    //Here we are taking the match of the XML opening tag and the correct data and replacing it with the XML opening tag and the string "BadData". For example, if you use "<XML>hey!</XML>" it will replace it with "<XML>BadData</XML>". If you want specific data in each cell just use it[1] (The opening XML tag) to grab a property named with it.
    def newXml = xml.replaceAll("<"+it[1]+">"+it[2],"<"+it[1]+">"+"BadData");

    //Putting the bad data into the testStep's request
    controlledStep.setPropertyValue("Request",newXml);

    //Running the testStep. Again, replace testName.
    def result = testRunner.runTestStepByName("testName");

    //I am just logging out the assertion. You can do anything you want here.
    log.info controlledStep.getAssertionStatus().toString();
    }

    //After it loops through every single child node, replacing only the values of that child node. I do not want to completely destroy the test step so I put the initial XML back into the test step. Always clean up your mess.
    controlledStep.setPropertyValue("Request",xml);



    If you need further assistance please ask. I commented it thoroughly so that you can hopefully see what is going on with the script. It's pretty simple overall.
  • eeyoreeco's avatar
    eeyoreeco
    Occasional Contributor
    PaulM wrote:
    Sure thing, I will set up a quick example script that you should be able to use that will perform these actions.



    //Setting up variables here.
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

    //Change "testName" to the name of the test step you are wanting to perform this on
    def holder = groovyUtils.getXmlHolder("testName#Request");
    def xml = holder.getPrettyXml();


    //This regexp grabs all child nodes that have a variable. Note for some odd reason, it leaves the '?' in the request and it also will not make any changes to any null or empty child nodes. The idea here is to start with a valid request
    def regexp = ("<([^<>]+)>(.*?)</\\1>");

    def matcher = xml =~ regexp;

    //Change testName here again. It might be a better idea to set this as a property or variable in the script.
    def controlledStep = testRunner.testCase.getTestStepByName("testName");

    //This section iterates through each of the regex matches
    matcher.each {


    //Here we are taking the match of the XML opening tag and the correct data and replacing it with the XML opening tag and the string "BadData". For example, if you use "<XML>hey!</XML>" it will replace it with "<XML>BadData</XML>". If you want specific data in each cell just use it[1] (The opening XML tag) to grab a property named with it.
    def newXml = xml.replaceAll("<"+it[1]+">"+it[2],"<"+it[1]+">"+"BadData");

    //Putting the bad data into the testStep's request
    controlledStep.setPropertyValue("Request",newXml);

    //Running the testStep. Again, replace testName.
    def result = testRunner.runTestStepByName("testName");

    //I am just logging out the assertion. You can do anything you want here.
    log.info controlledStep.getAssertionStatus().toString();
    }

    //After it loops through every single child node, replacing only the values of that child node. I do not want to completely destroy the test step so I put the initial XML back into the test step. Always clean up your mess.
    controlledStep.setPropertyValue("Request",xml);



    If you need further assistance please ask. I commented it thoroughly so that you can hopefully see what is going on with the script. It's pretty simple overall.


    Thanks Paul! I'll give a try for this one. Have a nice day!