当我 运行 在 soapUI 中使用 LAUNCH RUNNER 的项目时,我得到 "Cannot invoke method getProjectByName() on null object"

I am getting "Cannot invoke method getProjectByName() on null object" when i run the project with LAUNCH RUNNER in soapUI

我有一个控制器,它从 excel 获取测试数据,然后将它们传递到另一个名为 SERVICE_APP 项目的项目的属性中。

当我 运行 使用测试用例 SoapUI 时,控制器 运行 正确。但是当我从项目启动/测试套件启动中使用命令行/soapUI 运行 时出现错误 "getProjectByName() on null object"。

16:20:53,896 ERROR [SoapUI] An error occurred [Cannot invoke method getProjectB
Name() 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:
7)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMeta
lassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallS
teArray.java:45)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.
ava:32)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallS
teArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractC
llSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractC
llSite.java:116)
        at Script1.run(Script1.groovy:159)
        at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine
run(SoapUIGroovyScriptEngine.java:100)
        at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(
sdlGroovyScriptTestStep.java:154)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestS
ep(AbstractTestCaseRunner.java:239)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentT
stStep(WsdlTestCaseRunner.java:52)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internal
un(AbstractTestCaseRunner.java:152)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internal
un(AbstractTestCaseRunner.java:47)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(Abstract
estRunner.java:139)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

当我们 运行 从命令行/启动运行器

时,我们需要加载项目手册

http://forum.soapui.org/viewtopic.php?f=5&t=1449

这是因为在命令行运行时没有Workspace,所以无法通过这种方式访问​​其他项目。为了能够访问另一个项目,您需要手动加载它。这可以使用 ProjectFactoryRegistry 在 groovy 脚本中完成。

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"

@Siking : 感谢您尝试提供解决方案