Forum Discussion

SiKing's avatar
SiKing
Community Expert
12 years ago

custom event handler

Hello.
I am attempting to create my first custom event handler, as per http://www.soapui.org/Scripting-Propert ... dlers.html
I want my event to be applied at the end of any AMF step. I created Event = TestRunListener.afterStep and I set Target =
${=testStepResult instanceof com.eviware.soapui.impl.wsdl.teststeps.AMFTestStepResult}
However, my event is being applied to all steps. What is wrong?
TIA for any help.

5 Replies

  • Hi,

    I can't see anything wrong with your code. Could you log the result of the expression, just to verify that it works as expected. Just add this code to your event handler:

    log.info(testStepResult.name + ": " + (testStepResult instanceof com.eviware.soapui.impl.wsdl.teststeps.AMFTestStepResult))

    Kind regards,
    Manne Fagerlind
    SmartBear Sweden
  • SiKing's avatar
    SiKing
    Community Expert
    I have everything set up as above: the Event and Target. My entire script is:
    log.info testStepResult.getClass()

    I now run a test that has two steps: a JDBC and AMF. The script log says:
    Thu Sep 19 07:26:47 PDT 2013:INFO:class com.eviware.soapui.impl.wsdl.teststeps.JdbcTestStepResult
    Thu Sep 19 07:26:47 PDT 2013:INFO:class com.eviware.soapui.impl.wsdl.teststeps.AMFTestStepResult


    Of course the workaround (confirmed working) is:
    if(testStepResult instanceof com.eviware.soapui.impl.wsdl.teststeps.AMFTestStepResult) ...
    at the start of my script.
    But this seems like the Target functionality is not right?
  • I think the issue is with the use of "Target" field. As you can see in from http://www.soapui.org/Scripting-Propert ... dlers.html:
    * Target : an regex filter expression that will be applied for the corresponding target object when the event is triggered. Use this to narrow own invocations. This field can also contain property-expansions (see more below)

    So you can't just through in true/false in there. If your AMF steps have common part of step name, you could use "/*AMF*/" as target. But you may have to just surround your filter code with the working if statement:
    if(testStepResult instanceof com.eviware.soapui.impl.wsdl.teststeps.AMFTestStepResult) ...


    Thanks,
    Michael Giller
    SmartBear Software
  • SiKing's avatar
    SiKing
    Community Expert
    I think you did not read far enough in that link you posted, reading a bit further:
    The target also support property-expansion, and if this returns a boolean string "true" or "false", this value will be used (true will apply the filter, false will not). When using this with the script-property-expansion feature, you can for example enter as follows in an TestRunListener.afterTestStep target:

    ${=testStepResult.timeTaken > 50}

    This would evaluate the script and return "true" for those teststeps having taken more than 50 ms, thus applying the script only to them.

    note: emphasis is mine
  • Hi!

    We've verified that this is a bug and have registered an issue for it in our bug tracker (SOAP-677).
    We'll let you know as soon as we have more information about this.

    Sorry for the inconvenience.