Forum Discussion

SakshamArora's avatar
SakshamArora
New Contributor
12 years ago

Soap UI extension not working

Hi,

I am using free version of soapui. I have tried implementing Listener functionality as described in extending soapui section of the website. But, unfortunately i am not able to achieve the purpose of executing a code once test case(AfterRun function) is executed. The code used is:

package soapui.demo;

import java.util.*;
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;



public class DemoListener extends TestRunListenerAdapter

{

private long startTime;



public void beforeRun( TestCaseRunner testRunner, TestCaseRunContext runContext )

{

startTime = System.nanoTime();

}



public void afterRun( TestCaseRunner testRunner, TestCaseRunContext runContext )

{

List<TestStepResult> results=testRunner.getResults();
Iterator<TestStepResult> resultsIterator = results.iterator();
SoapUI.log("Checking Results::");
//int c=0;
// while( c < results.size() ){
// if( results.get(c).TestStepStatus.getStatus().toString() == "FAILED" )
// {
// String failedStepName=results.get(c).getTestStep().getLabel().toString();
// SoapUI.log("Failed at Step "+failedStepName);
// //String Response=results[c].getTestStep().getPropertyValue("Response").toString();
// String Response=runContext.getProperty(failedStepName,"Response").toString();
// SoapUI.log("Respose for failure: "+Response);

// }
// c++;
// }
while (resultsIterator.hasNext()) {
TestStepResult res=resultsIterator.next();
if (res.getStatus().toString() == "FAILED" ) {
String failedStepName=res.getTestStep().getLabel().toString();
SoapUI.log("Failed at Step "+failedStepName);
String Response=runContext.getProperty(failedStepName,"Response").toString();
SoapUI.log("Respose for failure: "+Response);
}
}



}


}


I have created jar of the classpath and added in ext folder as well. Also, my listeners. xml file is placed in listener folder. Please suggest how can I proceed with that.
  • Thanks for reply. But i am just looking to retrieve the Response of the failed testStep and want it to be displayed in the Soap UI logs at the time of execution. I have just modified the example available on soapui.org but its not working.
  • mayamit's avatar
    mayamit
    New Contributor
    I'm facing a similar issue even with the sample posted on the website. I followed all the instructions there, but I do not see any message appearing in the SoapUI log. Has anyone got this part working?
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    OK. In linux version, there was some minor issue in the soapui.sh which will affect loading, that was the reason for asking OS.
    Hope the listeners file naming convention is followed. i.e., file name should have format of <whatever>-listeners.xml.

    Do you see in the soapui.log that your listeners and jar file loaded?
  • SurajRao's avatar
    SurajRao
    New Contributor
    It's not working even for me, I am using SOAPUI 4.6.4 free version. Need help on this ASAP.

    performance-assertion-listeners.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">

    <tns:listener id="WagSvcPerfAssertionListener" listenerClass="soapui.WagSvcPerfAssertionListener" listenerInterface="com.eviware.soapui.model.testsuite.TestRunListener" />

    </tns:soapui-listeners>


    Java class

    package soapui;

    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;

    public class WagSvcPerfAssertionListener extends TestRunListenerAdapter
    {
    private long startTime;

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

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