Forum Discussion

mh350's avatar
mh350
Occasional Contributor
8 years ago

How to dynamically add Script Assertion, when addAssertion returns null

Hi 

 

I am trying to use groovy to add Script Assertion, I've found out in this forum I had to use addAssertion. Problem is that method returns null so I went back to this forum and I found this:

 

import com.eviware.soapui.config.AssertionEntryConfig
import com.eviware.soapui.impl.wsdl.teststeps.assertions.support.AssertionEntry
import com.eviware.soapui.config.AssertionTestStepConfig

def factoryinstance = AssertionTestStepConfig.Factory.newInstance()
def testStep = context.testCase.testSteps["Assertion TestStep"];
def source = context.testCase.testSteps["Test Request"];
def entry1 = new AssertionEntry(factoryinstance.insertNewEntry(0) , testStep.getTestStep() )
def parent = null
def entry = entry1.buildAssertionEntry("XPath Match", "Xpath", false, testStep, source, "Response",parent)
testStep.addAssertionEntry(entry)

which seems to have worked according to the discussion.

 

Question is how can I adapt it so it handles Script Assertion instead of  Xpath Assertion ?

 

Best regards!

3 Replies

  • mh350's avatar
    mh350
    Occasional Contributor

    Having done some more research it seems that AssertionEntry class is only available in SoapUI Pro which I haven't.

    Any suggestions ?

     

    Best regards.

    • axeltoushirou's avatar
      axeltoushirou
      Contributor

      I'm not sure if this can help, but you can add tons of assertion on a TestCase and you can disable/enable them with Groovy Script.

      So if you want this assertion to be used instead of another, then you can disable it. :)

       

      example:

      testRunner.testCase.testSteps["This is my testStep"].assertions["This is my assertion"].disabled = true

      this code is inside a Groovy Script not "Scipt Assertion"

      • mh350's avatar
        mh350
        Occasional Contributor

        Hi

         

        Actually the same code turns out to be working fine now (???),

        I still can't fathom what I was doing wrong.

        So basically it's all good.

         

        Best regards.