Forum Discussion

Glenn_Halstead's avatar
Glenn_Halstead
Occasional Contributor
16 years ago

java error when running from command line

Hi folks, 

I have a problem I hope someone can help with...

I have a groovy step that writes to a Project property using


def testProject = testRunner.testCase.testSuite.project.workspace.getProjectByName("ViewingCardManager_v15B4.0")
testProject.properties["mqResponse"].value = "blahblah"


Thus works fine when run in SoaupUI but when I run the same test case from the command line I get an error...

cmd line:

C:\Program Files\eviware\soapUI-2.5.1\bin>testrunner.bat -P "environment=D11" -c "requestViewingCard_UK1 TestCase" -r -a
-j -f C:\Osprey_Results "C:\Service_Testing\SCMS\SoapUI\ViewingCardManager_v15B4.0-soapui-project_gh.xml"


error:

13:43:51,631 ERROR [SoapUI] An error occured [Cannot invoke method getProjectByName() on null object], see error log for
details
java.lang.NullPointerException: Cannot invoke method getProjectByName() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:784)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
        at Script1.run(Script1.groovy:10)
        at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:59)
        at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runTestStep(WsdlTestCaseRunner.java:273)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.run(WsdlTestCaseRunner.java:182)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.start(WsdlTestCaseRunner.java:81)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:534)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:50)
        at com.eviware.soapui.tools.SoapUITestCaseRunner.runTestCase(SoapUITestCaseRunner.java:484)
        at com.eviware.soapui.tools.SoapUITestCaseRunner.runSuite(SoapUITestCaseRunner.java:443)
        at com.eviware.soapui.tools.SoapUITestCaseRunner.runRunner(SoapUITestCaseRunner.java:279)
        at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:127)
        at com.eviware.soapui.tools.AbstractSoapUIRunner.runFromCommandLine(AbstractSoapUIRunner.java:72)
        at com.eviware.soapui.tools.SoapUITestCaseRunner.main(SoapUITestCaseRunner.java:92)
13:43:51,662 ERROR [SoapUITestCaseRunner] putMQMesg failed, exporting to [C:\Osprey_Results\ViewingCardBinding_TestSuite
-requestViewingCardUK1_TestCase-putMQMesg-0-FAILED.txt]
13:43:51,693 INFO  [SoapUITestCaseRunner] Finished running soapUI testcase [requestViewingCard_UK1 TestCase], time taken


does anyone have any pointers?

thanks

Glenn
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello!

    This is due to the fact that there is no Workspace when running from command line, so you can't access other projects in this way. To be able to access another project, you need to manually load it. This can be done within the groovy script using the ProjectFactoryRegistry.

    So, if you want your code to work both in regular soapUI and when run from the command line, you can write something like this:


    import com.eviware.soapui.model.project.ProjectFactoryRegistry
    import com.eviware.soapui.impl.wsdl.WsdlProjectFactory

    def workspace = testRunner.testCase.testSuite.project.workspace
    def testProject = (workspace==null) ?
      ProjectFactoryRegistry.getProjectFactory(WsdlProjectFactory.WSDL_TYPE).createNew("<path to your project>.xml") :
      workspace.getProjectByName("ViewingCardManager_v15B4.0")
    if(!testProject.open && workspace!=null) workspace.openProject(testProject)

    testProject.properties["mqResponse"].value = "blahblah"


    Regards,
    Dain
    eviware.com