Hi John and Edinson,
You two are right. After the failed assertion, my code never reached "continue".
After I added try and catch for the assertion, continue worked. (please see 
code below)
However, the main Test Case appeared to be Passed after I catch this assertion 
error for this xml test step. I was going to show the assertion error and error 
logging in the Test Case.

if (startIndexDecision < 0){

log.info('Check Decision Code Failed because Pathway data does not contain 
Decision Code: '+decisionCode)

try {assert startIndexDecision >= 0, "Failed because "+decisionCode+" is not 
found in Pathway data, thus index is less than 0"}

catch (AssertionError e){
log.error("assertion error")
continue }
}





From: Edinson E. Padrón Urdaneta [mailto:edinson.padron.urdan...@gmail.com]
Sent: Tuesday, 12 January 2016 2:10 p.m.
To: users@groovy.apache.org
Subject: Re: "continue" does not continue the while loop after an assertion 
fails

I could be very wrong but I think that the problem is a logical one. If an 
assertion doesn't hold (if it fails), an exception will be thrown and the rest 
of the code won't be executed.

On Mon, Jan 11, 2016 at 8:20 PM, Deng, Lea 
<lea.d...@ccc.govt.nz<mailto:lea.d...@ccc.govt.nz>> wrote:
I'm using Soap UI and Groovy Script to go through a xml response with many 
Decision elements.
My Groovy Script refers to a DataSource 'Decision Exclusion List 
RMA/2010/33789' for a list of exlusion text to search for in the xml response.
I search for each DecisionCode read from the DataSource, then extract the xml 
lines for this DecisionCode element, then look for the exlusion text within 
them.
If the DecisionCode can not be found within the xml text, then I assert a 
failure, and continue the loop.
However, the test does not continue. It stops after the failed assertion.

Is that because "continue" does not work from within if { } ?
Thanks,
Lea

Please see my code below:

--------------------------------------------------

//(singleConsentString contains the xml text to search through)

def exlusionList = testRunner.testCase.testSteps['Decision Exclusion List 
RMA/2010/33789'] // refer to another DataSource test step to get a list of 
exlusion text


def counter = 0
while(exlusionList.next(testRunner,context)){
        counter ++
        log.info<http://log.info>("counter for decision exlusion list: " + 
counter)
        decisionCode = exlusionList.getPropertyValue('PathwayDecisionCode')
        decisionDescription = 
exlusionList.getPropertyValue('PathwayDecisionDescription')

        // search for the DecisionCode in xml text
        int startIndexDecision = 
singleConsentString.indexOf('<a:DecisionCode>'+decisionCode+'</a:DecisionCode>')
        log.info<http://log.info>('logging start index of Decision:  ' + 
startIndexDecision)

        // if DecisionCode is not found, assert a failure, and continue the 
loop;
        if (startIndexDecision < 0){
                log.info<http://log.info>('Check Decision Code Failed because 
Pathway data does not contain Decision Code: '+decisionCode)
                assert startIndexDecision >= 0, "Failed because 
"+decisionCode+" is not found in Pathway data, thus index is less than 0"
                continue // this does not work
        }

        // if DecisionCode is found, then extract the xml lines for this 
DecisionCode, and check for DecisionDescription as well.
        else {
                String subStringDecision = 
singleConsentString.substring(startIndexDecision)
                int endIndexDecision = 
subStringDecision.indexOf('</a:DecisionEntity>')
                singleDecisionString = 
subStringDecision.substring(0,endIndexDecision)
                log.info<http://log.info>('logging singe decision:  '+ 
singleDecisionString)

                assert singleDecisionString.contains(decisionCode)&& 
singleConsentString.contains(decisionDescription)
        }
}


**********************************************************************
This electronic email and any files transmitted with it are intended
solely for the use of the individual or entity to whom they are addressed.

The views expressed in this message are those of the individual sender
and may not necessarily reflect the views of the Christchurch City Council.

If you are not the correct recipient of this email please advise the
sender and delete.

Christchurch City Council
http://www.ccc.govt.nz
**********************************************************************

**********************************************************************
This electronic email and any files transmitted with it are intended
solely for the use of the individual or entity to whom they are addressed.

The views expressed in this message are those of the individual sender
and may not necessarily reflect the views of the Christchurch City Council.

If you are not the correct recipient of this email please advise the
sender and delete.

Christchurch City Council
http://www.ccc.govt.nz
**********************************************************************

Reply via email to