Ask a Question

Continue Assertions in Groovy Step when one assertion fails

Teltstra_Corpor
Occasional Contributor

Continue Assertions in Groovy Step when one assertion fails

We are using SoapUI Pro with Test Cases where we write assertions inside Groovy Steps.

Test Step: Groovy Script Step

//Assertion 1
def ProductOfferingCode = context.expand(...something...)
assert ProductOfferingCode == 'something'

//Assertion 2
def productOfferingSource = context.expand(...something...)
assert productOfferingSource == 'something'

//Assertion 3
def isSubscription = context.expand(...something...)
assert isSubscription == 'something'

When Assertion 1 fails, SoapUI Pro will "Exit" the Groovy Step, and go to next step in Test Case.

How can I force SoapUI to continue with Assertion 2 and Assertion 3, even when Assertion 1 fails.

Also, I already know about the "Abort on Error" option, which continues to the next step when one step fails. But what I need is to continue with other assertions in the same Groovy step.

Regards,
Jatin Kumar
4 REPLIES 4
SmartBear_Suppo
SmartBear Alumni (Retired)

HI,

in groovy
assert ProductOfferingCode == 'something' throws AssertionException so the flow of the script ends there.

Here is the simple tweak



def assertionList = []
//Assertion 1
def ProductOfferingCode = context.expand(...something...)
ProductOfferingCode == 'something' ? log.info "Assertion1 pass" : assertionList.add("Assertion1 fails")

//Assertion 2
def productOfferingSource = context.expand(...something...)
productOfferingSource == 'something' ? log.info "Assertion2 pass" : assertionList.add("Assertion2 fails")


//Assertion 3
def isSubscription = context.expand(...something...)
isSubscription == 'something' ? log.info "Assertion3 pass" : assertionList.add("Assertion3 fails")


assert assertionList.isEmpty() : assertionList.toString()


So you can add which assertions failed and if there is something in assertionList it means that somethig failed.

Hope this helps

regards
nebojsa
SmartBEar Software

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

It is not working for me , Got compilation error

nmrao
Champion Level 2

Hoping that you may find the below thread & its comments helpful in this case.

http://stackoverflow.com/questions/28497207/how-to-fail-a-script-assertion-in-soapui/28497531#284975...


Regards,
Rao.

Once again thank you so much @nmrao Smiley Happy

Your comments solved my problem,

def error = []
if (jsonid != dbid) {error.add("jsonid : $jsonid is not equal to dbid: $dbid")}
if (jsonname != dbname) {error.add("jsonname : $jsonname is not equal to dbname: $dbname")}

assert error.size() == 0," $error " 
if(error.size() == 0){ log.info "Script Passed" }
cancel
Showing results for 
Search instead for 
Did you mean: