cancel
Showing results for 
Search instead for 
Did you mean: 

Continue Assertions in Groovy Step when one assertion fails

Highlighted
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
Highlighted

Re: Continue Assertions in Groovy Step when one assertion fa

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. ⬇️⬇️⬇️Please mark my answer as a solution if it was helpful
Highlighted
Contributor

Re: Continue Assertions in Groovy Step when one assertion fa

It is not working for me , Got compilation error

Highlighted
Community Hero

Re: Continue Assertions in Groovy Step when one assertion fails

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.
Highlighted
Contributor

Re: Continue Assertions in Groovy Step when one assertion fails

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" }
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors