Forum Discussion

Kronos_-_soapUI_1's avatar
Kronos_-_soapUI_1
Occasional Contributor
13 years ago

[Res] wsdlProject.getTestSuite returns null unless project..

Hi. Can you tell me why the wsdlProject.getTestSuiteByName("TestCase Library")
returns null unless the project is open in the SoapUI GUI? Thanks.

import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlTestSuite
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase


WsdlProject wsdlProject = (WsdlProject) testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("TestCase Library")
log.info wsdlProject.getPath()

WsdlTestSuite wsdlTestSuite = wsdlProject.getTestSuiteByName("TestCase Library")
//wsdlTestSuite is null unless project is open in the SoapUI GUI. Why?
WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("SetGlobalProperties")
wsdlTestCase.run(new StringToObjectMap(context),false)

9 Replies

  • Hi!

    Well, this is by design as you shouldn't be able to open TestSuites on a closed project.
    However, the method should probably throw an explanatory "ProjectClosedException" instead of just returning a (somewhat evil) null.
    Do you want us to create a improvement for that?

    Also, you could check if an project is closed by using
    wsdlProject.isOpen()


    ---
    Regards
    Erik
    SmartBear Support
  • Kronos_-_soapUI_1's avatar
    Kronos_-_soapUI_1
    Occasional Contributor
    Hi Erik - actually that code was never going to work due to the ClassCastException between WsdlProjectPro and WsdlProject. This is the code I'm using now.

    import com.eviware.soapui.impl.wsdl.WsdlProjectPro
    import com.eviware.soapui.impl.wsdl.WsdlTestSuite
    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase

    workspace = testRunner.getTestCase().getTestSuite().getProject().getWorkspace()
    wsdlProject = workspace.getProjectByName("TestCase Library")
    libraryPath = wsdlProject.getPath()

    tcLibrary = new WsdlProjectPro(libraryPath)

    WsdlTestSuite wsdlTestSuite = tcLibrary.getTestSuiteByName("TestCase Library")
    WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("SetGlobalProperties")

    wsdlTestCase.run(new StringToObjectMap(context),false)
  • Kronos_-_soapUI_1's avatar
    Kronos_-_soapUI_1
    Occasional Contributor
    Hi Erik. What I'm really trying to do is open a Project programatically that will work on both Pro and Free versions. We run our automation on the free version (for now, request is in), but develop in Pro. How can I open a project so that it will work in both versions? For example:

    import com.eviware.soapui.impl.wsdl.WsdlProjectPro
    import com.eviware.soapui.impl.wsdl.WsdlTestSuite
    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase

    workspace = testRunner.getTestCase().getTestSuite().getProject().getWorkspace()
    wsdlProject = workspace.getProjectByName("TestCase Library")
    libraryPath = wsdlProject.getPath()

    try {
    tcLibrary = new com.eviware.soapui.impl.wsdl.WsdlProjectPro(libraryPath)
    }
    catch (Throwable t) {
    tcLibrary = new com.eviware.soapui.impl.wsdl.WsdlProject(libraryPath)
    }

    WsdlTestSuite wsdlTestSuite = tcLibrary.getTestSuiteByName("TestCase Library")
    WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("SetGlobalProperties")

    wsdlTestCase.run(new StringToObjectMap(context),false)


  • Kronos_-_soapUI_1's avatar
    Kronos_-_soapUI_1
    Occasional Contributor
    Hi Erik. I dived into this a little more, and isolated where the ClassCastException is coming from. Take the following code snippet:

    import com.eviware.soapui.impl.wsdl.WsdlProject
    import com.eviware.soapui.impl.wsdl.WsdlProjectPro
    import com.eviware.soapui.impl.wsdl.WsdlTestSuite
    import com.eviware.soapui.support.types.StringToObjectMap
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase

    workspace = testRunner.getTestCase().getTestSuite().getProject().getWorkspace()
    wsdlProject = workspace.getProjectByName("TestCase Library")
    libraryPath = wsdlProject.getPath()

    def tcLibrary = new com.eviware.soapui.impl.wsdl.WsdlProject(libraryPath)

    WsdlTestSuite wsdlTestSuite = tcLibrary.getTestSuiteByName("TestCase Library")
    WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("SetGlobalProperties")
    wsdlTestCase.run(new StringToObjectMap(context),false)



    The line: wsdlTestCase.run(new StringToObjectMap(context),false) is causing the following stack trace. I am not using any pro features in my testcase. Why is the run method on WsdlTestCase trying to cast WsdlProject to WsdlProjectPro ?

    Mon Nov 26 10:31:31 EST 2012:ERROR:java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.WsdlProject cannot be cast to com.eviware.soapui.impl.wsdl.WsdlProjectPro
    java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.WsdlProject cannot be cast to com.eviware.soapui.impl.wsdl.WsdlProjectPro
    at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:55)
    at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:49)
    at com.eviware.soapui.eventhandlers.impl.EventHandlersTestRunListener.beforeRun(SourceFile:50)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.notifyBeforeRun(AbstractTestCaseRunner.java:320)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:117)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:42)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:135)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77)
    at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:638)
    at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:73)
    at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
    at Script15.run(Script15.groovy:18)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Mon Nov 26 10:31:31 EST 2012:ERROR:java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.WsdlProject cannot be cast to com.eviware.soapui.impl.wsdl.WsdlProjectPro
    java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.WsdlProject cannot be cast to com.eviware.soapui.impl.wsdl.WsdlProjectPro
    at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:55)
    at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:49)
    at com.eviware.soapui.eventhandlers.impl.EventHandlersTestRunListener.afterRun(SourceFile:31)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.notifyAfterRun(AbstractTestCaseRunner.java:300)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalFinally(AbstractTestCaseRunner.java:190)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalFinally(AbstractTestCaseRunner.java:42)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:163)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77)
    at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:638)
    at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:73)
    at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
    at Script15.run(Script15.groovy:18)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
  • Hmm...

    So you get this error when running the Pro version from the GUI?
    The project you are trying to run, has that been created in the Open Source version of soapUI?

    --
    Regards

    Erik
    SmartBear Sweden
  • Kronos_-_soapUI_1's avatar
    Kronos_-_soapUI_1
    Occasional Contributor
    Hi Eric. Yes, I am getting a ClassCastException from the bowels of the run method when run in the Pro UI. I've not even tried the command line free version yet. In effect, WsdlProject is unusable from Pro. I've reproduced this with two different configurations. This is 4.5.1.
  • Kronos_-_soapUI_1's avatar
    Kronos_-_soapUI_1
    Occasional Contributor
    Hi Erik. I've worked around the problem by dynamically loading WsdlProjectPro if it's not running from the command line. This works for my situation, and it compiles and executes fine when run from the command line in the open source version. I know there are easier ways to get the project handle , but this is what I was using as I was stumbling around for a solution.

    import com.eviware.soapui.impl.wsdl.WsdlProject
    import com.eviware.soapui.impl.wsdl.WsdlTestSuite
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    import java.io.File

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
    def thisProjectDir = groovyUtils.projectPath
    File f = new File(thisProjectDir, "\\..\\MyProject\\MyProject.xml");
    String absolute = f.getCanonicalPath()

    if (!com.eviware.soapui.SoapUI.isCommandLine())
    // running in the ProUI
    {
    project = Class.forName("com.eviware.soapui.impl.wsdl.WsdlProjectPro").newInstance(absolute);
    }
    else {
    // running in the free version via testRunner.bat
    project = new WsdlProject(absolute)
    }