Forum Discussion

brr7907's avatar
brr7907
Occasional Contributor
15 years ago

Trouble with Demo Listener Example

I'm new to SoapUI and have been very excited to try out the extensions.  I started with the Java examples here -> http://soatoolbox.com/architecture/extensions.html and I immediately had success with the Action, but I'm struggling with the Listener.

I'm hoping a more seasoned user might be able to get me over this hurdle.

I can see that the demo-listeners.xml is being loaded.  I can also see that the SoapUIActionExt.jar file with the DemoListener class is being loaded. 

The problem is that I don't see any output when I run a Test Case.  If I understand the example correctly the amount of time to run the Test Case should be written to the soapUI log.  I don't see it.  I have also tried versions of DemoListener.java that would immediately throw a RuntimeException hoping to see an error popup somewhere with no success.  It sure seems like the DemoListener is not being called.

I have attached the DemoListener.java source file and the contents of soapUI log after restarting SoapUI and running a Test Case.

Note: I did make one change to the DemoListener.java listed online.  I removed the code to dynamically determine the name of the TestCase since it seems that the example code will not compile since  TestRunner does not have a getTestCase() method.

I am currently using SoapUI 3.0

Thanks in advance for the help.

4 Replies

  • brr7907's avatar
    brr7907
    Occasional Contributor
    After a good nights sleep and a second look.  I figured out the problem.  The problem is in the example located here -> http://www.soapui.org/architecture/extensions.html

    The example on the website has a classic Java mistake, overloaded...not overidden methods.  The website has this for the following signatures...

    public void beforeRun( TestRunner testRunner, TestRunContext runContext )
    ...
    public void afterRun( TestRunner testRunner, TestRunContext runContext )


    According to the JavaDocs (and an example that works for me) the signatures should have been...
    public void beforeRun(TestCaseRunner testRunner, TestCaseRunContext runContext) {
    ...
    public void afterRun(TestCaseRunner testRunner, TestCaseRunContext runContext){
  • xman's avatar
    xman
    New Contributor
    I have tried and tried but the DemoListener does not work for me.
    Running SOAPUI 3.5 Pro...
    Have included comments from the post above but still get nothing in my SOAPUI log.
    I see
    Fri May 21 15:56:44 EDT 2010:INFO:Adding listeners from [C:\Program Files\eviware\soapUI-Pro-3.5\bin\listeners\demo-listeners.xml]

    Fri May 21 15:56:44 EDT 2010:INFO:Adding listener [class soapui.demo.DemoListener]

    but never anything in my log....
    Does this really work???

    package soapui.demo;

    import com.eviware.soapui.SoapUI;
    import com.eviware.soapui.model.support.TestRunListenerAdapter;
    import com.eviware.soapui.model.testsuite.TestRunContext;
    import com.eviware.soapui.model.testsuite.TestRunner;
    import com.eviware.soapui.model.testsuite.TestCaseRunner;

    public class DemoListener extends TestRunListenerAdapter
    {
    private long startTime;

    public void beforeRun( TestCaseRunner testRunner, TestRunContext runContext )
    {
    SoapUI.log ("Time starts now Gus!");
    startTime = System.nanoTime();
    }

    public void afterRun( TestCaseRunner testRunner, TestRunContext runContext )
    {
                    SoapUI.log ("Were done now ..phew");
    long endTime = System.nanoTime();
    SoapUI.log( "Jerry Time TestCase [" + testRunner.getTestCase().getName() + "] took " + (endTime-startTime) +
        " nanoseconds." );
    }


    }
  • dannyparadis's avatar
    dannyparadis
    Occasional Contributor
    I received this response from support.
    It works fine with the update! ;-)
    bye

    ---------------------------------------------------
    Hello,

    You are not implementing listener class correctly, methods should be:

    public void beforeRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
    public void afterRun( TestCaseRunner testRunner, TestCaseRunContext runContext )

    not

    public void beforeRun(TestRunner testRunner, TestRunContext runContext)
    public void afterRun(TestCaseRunner testRunner, TestRunContext runContext)

    Please see, API docs in Developers corner on www.soapui.org. I guess this since our documentation
    was wrong. We fixed it. Sorry for inconvenience.

    Let me know does this helps,
    robert