Forum Discussion

koen_able's avatar
koen_able
Occasional Contributor
5 years ago
Solved

SoapUI Jenkins: how to use TestSuiteRunListener

Hi,

I have a test pipeline running in Jenkins with a SoapUI node connected to it. I want to run a script (in a test suite, in a testcase) ONE time before I start running my testsuite (I have only one for now). I thought about using the Event TestRunListener.beforeRun, but that will run the script everytime a test case starts. Then I thought about using the  TestSuiteRunListener.beforeRun. But that one gave the following exception:

08:59:45 08:59:45,811 ERROR [EventHandlersRequestFilter] com.eviware.soapui.support.scripting.ScriptException: Error in TestSuiteRunListener.beforeRun
08:59:45 08:59:45,817 ERROR [SoapUI] An error occurred [Error in TestSuiteRunListener.beforeRun], see error log for details
08:59:45 08:59:45,818 ERROR [errorlog] com.eviware.soapui.support.scripting.ScriptException: Error in TestSuiteRunListener.beforeRun
08:59:45 com.eviware.soapui.support.scripting.ScriptException: Error in TestSuiteRunListener.beforeRun
08:59:45 Caused by: groovy.lang.MissingPropertyException: No such property: testCase for class: com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner

Apparently there is something wrong with the following code that I use:

// Check if the test case is run from the command line
if (com.eviware.soapui.SoapUI.isCommandLine()) {
   log.info "This code is executed by Command Line SoapUI"
   log.info "Now running setup scripts"
   def testCase = testRunner.testCase.testSuite.project.testSuites['testsuite'].testCases['testcase']
   def testStep = testCase.getTestStepByName("teststep")
   testStep.run( testRunner, context )
}

It doesn't recognize testCase for class: com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner used here:

def testCase = testRunner.testCase.testSuite.project.testSuites['testsuite'].testCases['testcase']

So how do I script to have the testRunner run the testcase 'Setup Project' in the testsuite 'tooling-general' using the estSuiteRunListener.beforeRun?

  • The following code worked for me with the help of Smartbear and this Smartbear community topic:

    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
    
    def testcase = testRunner.getTestSuite().getProject().getTestSuiteByName("testsuite").getTestCaseByName("testcase") 
    
    if(testcase != null)
    {
    	WsdlTestCaseRunner wtcr = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testcase, new com.eviware.soapui.support.types.StringToObjectMap()) 
    	testcase.getTestStepByName("teststep").run(wtcr ,wtcr.createContext(null)) 
    
    }

     

3 Replies

  • Olga_T's avatar
    Olga_T
    SmartBear Alumni (Retired)

    Hi koen_able,

     

    As far as I can see in our DB, you are currently working with one of our support engineers on this question. It would be great if you could update us on the progress here in the Community.

    Thank you in advance!

  • koen_able's avatar
    koen_able
    Occasional Contributor

    The following code worked for me with the help of Smartbear and this Smartbear community topic:

    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
    
    def testcase = testRunner.getTestSuite().getProject().getTestSuiteByName("testsuite").getTestCaseByName("testcase") 
    
    if(testcase != null)
    {
    	WsdlTestCaseRunner wtcr = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testcase, new com.eviware.soapui.support.types.StringToObjectMap()) 
    	testcase.getTestStepByName("teststep").run(wtcr ,wtcr.createContext(null)) 
    
    }