Forum Discussion

lagap's avatar
lagap
New Contributor
16 years ago

Adding Script assertions dinamically

I am a newbie to SoapUI, I am using soapui-pro-2.0.2.
I am trying to add script assertions dynamically through a groovy script.
Below is the code being used.

def assertion = testRunner.getTestCase().getTestStepByName("Request").addAssertion("Script Assertion")
assertion.name = "ScriptAssert1"
assertion.a(assertion,”assert(1==2)”)

Assertion is being shown as passed (1==2) after request execution.
However, if I open the assertion from the GUI and touch it (Add a space), it shows the right result (Which is fail).
Can you please point me, if I am adding the script assertion in wrong way?

Thankyou

4 Replies

  • lagap's avatar
    lagap
    New Contributor
    Was able to get it working with soapui-pro-2.5.1. There seems to be a bug in the earlier version.

    Thankyou
  • Awesome's avatar
    Awesome
    Frequent Contributor
    hi i was trying to copy the above example, but i get the following error:

    groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.assertions.ProGroovyScriptAssertion.a() is applicable for argument types: (com.eviware.soapui.impl.wsdl.teststeps.assertions.ProGroovyScriptAssertion, java.lang.String) values: {com.eviware.soapui.impl.wsdl.teststeps.assertions.ProGroovyScriptAssertion@9cf715, "assert(1==2)"}


    --------------------code-------------

    import com.eviware.soapui.SoapUI;
    import com.eviware.soapui.model.testsuite.*;

    def assertion = testRunner.getTestCase().getTestStepByName("q1").addAssertion("Script Assertion")
    assertion.name = "ScriptAssert1"
    assertion.a(assertion, "assert(1==2)")
  • Awesome's avatar
    Awesome
    Frequent Contributor
    so this code seems to work:


    ----
    import com.eviware.soapui.SoapUI;
    import com.eviware.soapui.model.testsuite.*;
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.*;

    def assertion = testRunner.getTestCase().getTestStepByName("q1").addAssertion("Script Assertion")
    log.info assertion.getClass().getName()
    assertion.name = "ScriptAssert1"
    assertion.setScriptText("assert(1==1)")
  • Hi !

    What i had to do aditionally to get it running (v2.5.1) :

     assertion.setConfiguration(assertion.createConfiguration());


    Without this line of code, project.saveAs("...") did not save my ScriptText !

    Is this a bug ?

    Krösi