cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED]Allow wildcards when adding assertion with groovy

SOLVED
Frequent Contributor

[SOLVED]Allow wildcards when adding assertion with groovy

Hi,

Is there anyway to set the "Allow Wildcard"  flag programatically when adding an assertion with groovy? Here is the code that I am using to add the assertion:

def static addAssertion(assertionName,requestName,expectedContent,testRunner,log)
   {
try
{
switch (assertionName)
{
case "XPath Match":
def assertion = testRunner.getTestCase().getTestStepByName(requestName).addAssertion("XPath Match")
assertion.name = assertionName
assertion.path = "declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';soapenv:Envelope[1]"
assertion.expectedContent = expectedContent
break;
case "SOAP Response":
def assertion=testRunner.getTestCase().getTestStepByName(requestName).addAssertion("SOAP Response")
assertion.name = "SOAP Response"
break;
default:
log.info ("There is no case for " + assertionName + " in addSimpleAssertion")
break;
}
}
catch (Exception e)
{
throw new Exception( e );
}
   }

}

Thanks,
Mary
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Allow wildcards when adding assertion with groovy

You can call setAllowWidlcards(true) on the assertion to allow wildcards.

/Nenad
http://eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Community Leader

Re: Allow wildcards when adding assertion with groovy

I would recommend starting a new topic rather than resurecting a 9 year old thread, but...

 

The setAllowWidlcards() method is specified by the AbstractXmlContainsAssertion class. The classes XPathContainsAssertion and XQueryContainsAssertion both extend this abstract class.

6 REPLIES 6

Re: Allow wildcards when adding assertion with groovy

Are the assertions already defined? Or do you define them elsewhere in the script. If they are defined using the assertion interface, you can just allow wildcards there.

/Nenad
http://eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Frequent Contributor

Re: Allow wildcards when adding assertion with groovy

I'm dynamically removing the testcase, then creating the request and assertion each time I run the testcase, so the assertions are not already defined and I can't use the assertion interface.  Is there anyway to do this through the soapui API?  If not, can this be added in the future?

Thanks,

Mary

Re: Allow wildcards when adding assertion with groovy

You can call setAllowWidlcards(true) on the assertion to allow wildcards.

/Nenad
http://eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Highlighted
Frequent Contributor

[Resolved] Re: Allow wildcards when adding assertion with groovy

Thanks, that worked!!

The javadocs for the SoapUI API are a little hard to figure out and google was no help. Also I couldn't find it in this forum.  Thanks for your time.

Mary
Occasional Contributor

Re: Allow wildcards when adding assertion with groovy

Hi, can you give an example of how to do this? I can't find any reference to  setAllowWidlcards(true) anywhere apart from this specific case!

Community Leader

Re: Allow wildcards when adding assertion with groovy

I would recommend starting a new topic rather than resurecting a 9 year old thread, but...

 

The setAllowWidlcards() method is specified by the AbstractXmlContainsAssertion class. The classes XPathContainsAssertion and XQueryContainsAssertion both extend this abstract class.

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors