Forum Discussion

mkmichem's avatar
mkmichem
New Contributor
14 years ago

Test Automation: Maven with custom listener

Hello everyone,

I'm using SoapUI pro.
I would like to install a custom listener to the SoapUI Maven plug-in.

I have created a custom implementation of a SoapUI listener as follows:

public class IqsSoapUIListener extends TestRunListenerAdapter {
// Override method calls with custom implementation
}


Now I would like to inject this custom listener within the SoapUI maven plug-in.
Where / how can I add my custom listener to the SoapUI Maven plug-in.

Thanks,
Michael
  • mkmichem's avatar
    mkmichem
    New Contributor
    Hello mlenosgrande,

    Thank you so much for your response ...
    ok ... so the JAR will be picked up from the classpath ...
    but the XML file ... i'm assuming that the *-listeners.xml file
    needs to be placed under some directory for the maven plugin to pick it up ?
  • i'm assuming that the *-listeners.xml file
    needs to be placed under some directory for the maven plugin to pick it up ?

    Yes, but i dont know as much as you bout know.

    I can give you the direct solution but it will be more effective to give you for my heuristic search pattern reusable many times

    According to you the *-listener.xml have to be in the /bin/listeners. But how Soapui can know that ? Black Magic >:D , hard coded in the java code or a parameter ?

    We know that the Gui one is launched by a script adding differents variables.
    So let see the content of soapui.bat

    if "%SOAPUI_HOME%" == "" goto START
    set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.libraries="%SOAPUI_HOME%ext"
    set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.listeners="%SOAPUI_HOME%listeners"

    Youpi ! Dsoapui.ext.listeners is a parameter.

    Just to be sure let apply a double check with Google Source Code

    By the way, this tool is most effective tool to search for real example and able to apply easily my favourite copy/paste pattern )

    Back to Soapui, the response is
    here :

     System.getProperty( "soapui.ext.listeners" );


    Now we have to find a way to tell to maven eviware plugin to apply the mirror instruction:

     System.setProperty("soapui.ext.listeners", myValue)
    portion of code.
    I havent test ot but this may make it.

    ...
    <configuration>
    <soapuiProperties>
    <property>
    <name>soapui.ext.listeners</name>
    <value>${project.build.testOutputDirectory}/soapui/myListener.xml</value>
    </property>
    </soapuiProperties>



    And how to be sure it will loaded ? maybe like usual they have a log added
    And the answer is yes according to this line of code. You will read on the console :
    "Adding listeners from your_Path_Specify_inMaven


    Omar elmandour
  • mkmichem's avatar
    mkmichem
    New Contributor
    Fantastic, I could not have asked for a better explanation.
    I will post the final outcome soonest.

    Thanks again, you have helped me a lot mlenosgrande, it is much appreciated
  • mkmichem's avatar
    mkmichem
    New Contributor
    For those who would like to hear the final word:

    Add the listener jar file under a folder named 'ext' of the project root.
    Add the *-listeners.xml file under a folder named 'listeners' of the project root.

    The soapui maven plugin will treat the maven project it's attached to as SOAPUI_HOME,
    and pick up the jar's or files under those two folders automatically.

    Perhaps someone could add this to the SoapUI documentation.

    -Michael
  • sentinel's avatar
    sentinel
    New Contributor
    I'm able to see the listeners loaded in the soapui.log, but i don't see the log messages from calls to SoapUI.log() in the log. i.e. no indication that the Listener is listening.

    see code and log below.


    2012-05-01 17:09:31,570 INFO [SoapUI] Adding [/home/cjt/work/LoadUIPOC/./ext/LoadUIPOC-1.0-SNAPSHOT.jar] to extensions classpath
    2012-05-01 17:09:31,570 INFO [DefaultSoapUICore] Creating new settings at [/home/cjt/soapui-settings.xml]
    2012-05-01 17:09:31,875 INFO [DefaultSoapUICore] Adding listeners from [/home/cjt/work/LoadUIPOC/./listeners/POC-listeners.xml]
    2012-05-01 17:09:31,917 INFO [DefaultSoapUICore] Adding listener [class com.epsilon.qualitymgt.perfnscale.loadui.PerfTestRunListener]
    2012-05-01 17:09:32,252 INFO [WsdlProject] Loaded project from [file:/home/cjt/work/LoadUIPOC/LoadUIPOC-soapui-project.xml]
    2012-05-01 17:09:32,574 INFO [SoapUITestCaseRunner] Running soapUI tests in project [LoadUIPOC]
    2012-05-01 17:09:32,574 INFO [SoapUITestCaseRunner] Running TestCase [Load_LoadUIPOC_HOME]
    2012-05-01 17:09:32,578 INFO [SoapUITestCaseRunner] Running soapUI testcase [Load_LoadUIPOC_HOME]
    2012-05-01 17:09:32,582 INFO [SoapUITestCaseRunner] running step [http://localhost:8080/app/]
    2012-05-01 17:09:32,729 INFO [SoapUITestCaseRunner] Assertion [Contains] has status VALID
    2012-05-01 17:09:32,730 INFO [SoapUITestCaseRunner] Finished running soapUI testcase [Load_LoadUIPOC_HOME], time taken: 71ms, status: FINISHED
    2012-05-01 17:09:32,730 INFO [SoapUITestCaseRunner] TestCase [Load_LoadUIPOC_HOME] finished with status [FINISHED] in 71ms

    $ cat POC-listeners.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">
    <tns:listener id="PerfTestRunListener"
    listenerClass="com.epsilon.qualitymgt.perfnscale.loadui.PerfTestRunListener"
    listenerInterface="com.eviware.soapui.model.testsuite.TestRunListener" />
    </tns:soapui-listeners>


    $ cat PerfTestRunListener.java
    package com.epsilon.qualitymgt.perfnscale.loadui;

    import com.eviware.soapui.SoapUI;
    import com.eviware.soapui.model.support.TestRunListenerAdapter;
    import com.eviware.soapui.model.testsuite.TestCaseRunContext;
    import com.eviware.soapui.model.testsuite.TestCaseRunner;
    import com.eviware.soapui.model.testsuite.TestStepResult;
    import com.eviware.soapui.model.testsuite.TestStep;

    public class PerfTestRunListener extends TestRunListenerAdapter {
    private long runStartTime;
    private long stepStartTime;

    public void beforeRun(TestCaseRunner testRunner, TestCaseRunContext runContext) {
    runStartTime = System.nanoTime();
    }

    public void afterRun(TestCaseRunner testRunner, TestCaseRunContext runContext) {
    long runEndTime = System.nanoTime();
    SoapUI.log("PerfTest TestCase [" + testRunner.getTestCase().getName() + "] took " + (runEndTime-runStartTime) + " nanoseconds.");
    }

    public void beforeStep(TestCaseRunner testRunner, TestCaseRunContext runContext, TestStep step) {
    stepStartTime = System.nanoTime();
    SoapUI.log("beforeStep [" + step.getName() + "] at " + stepStartTime);
    }

    public void afterStep(TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult stepResult) {
    long stepEndTime = System.nanoTime();
    //SoapUI.log("afterStep [" + stepResult.getTestStep().getName() + "] took " + (stepEndTime-stepStartTime) + " nanoseconds.");
    SoapUI.log("afterStep [" + stepResult.getTestStep().getName() + "] at " + stepEndTime);
    }
    }


    Thanks,

    Carlos
  • sentinel's avatar
    sentinel
    New Contributor
    Would it be possible to get some feedback on the code above, and whether or not it is correct? the Listener doesn't seem to be Listening...
  • sentinel's avatar
    sentinel
    New Contributor
    Nevermind, i appears to be listening. it just doesn't log to soapui.log as the method SoapUI.log() would suggest.

    --Carlos