cancel
Showing results for 
Search instead for 
Did you mean: 

Assertion Script

Highlighted
Occasional Contributor

Assertion Script

Have read all the docu and searched this forum, but still don't see how to do this....

I have a CONTAINS assertion in a Test Step which I now want to put in a groovy script.

Have this code:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

def holder = groovyUtils.getXmlHolder( "Test_Request_sPUA#Response" )

How can I test with an assertion if the response stored in holder contains the string "" ?

Tnks, Kevin
4 REPLIES 4
Highlighted

Re: Assertion Script

Hello,

You can do it without assertion in groovy like this :


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Test_Request_sPUA#Response" )
if (holder.xml.indexOf("<Produkt>") > -1)
log.info "have it"
else
log.info "don't have it"


robert

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
Occasional Contributor

Re: Assertion Script

Thank you very much, that works fine.

I have set up an excel datasink which successfully collects the material_number used and now I want to write in the columns beside it whether the product for this material-number was found or not.

Have the following code in my test step groovy script and a property called produkt_found in my datasink_excel step:

def response = holder.getXml()


if (holder.xml.indexOf("") > -1)
{
log.info "have it"
produkt_found = "Found"
}
else
{

log.info "don't have it";

produkt_found = "Not found"   
    }

So my question is, what code do I need in the value box of the property in the datasink so that it collects the value "Found" or "Not Found" set by the groovy script?

I promise sincerely that I have rtfm and googled my socks off before posting this
Highlighted

Re: Assertion Script

Hello!

The variables set in the groovy script are lost once the script is done executing. What you need to do is store the values directly to the data sink from the script. This is done as follows:


def response = holder.getXml()


if (holder.xml.indexOf("<Produkt>") > -1)
{
  log.info "have it"
  testRunner.testCase.testSteps['DataSink'].properties['produkt_found'].value = 'Found'
}
else
{
  log.info "don't have it"
  testRunner.testCase.testSteps['DataSink'].properties['produkt_found'].value = 'Not Found'
}


(Replace 'DataSink' with the name of your DataSink teststep)

Regards,
Dain
eviware support

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
Occasional Contributor

Re: Assertion Script

That hit the spot!  Will check out the testRunner stuff, many thanks... 
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