2016-11-24 65 views
0

是否有可能确定是否了SoapUI(ReadyAPI)经由testrunner.bat 开始确定是否了SoapUI(ReadyAPI)经由testrunner.bat或由用户启动的(在UI模式下运行)

  1. 用户(在交互UI模式下运行)

我知道,你可以使用这个Groovy脚本代码检索当前环境:

def env = testRunner.testCase.testSuite.project.activeEnvironment.name 

但是,我想知道通过命令行(testrunner.bat)运行时会返回什么值。它会从测试项目返回活动环境,还是会为空/空?


更新(用例)
用户的情况是取决于方式的测试运行。在testrunner.bat的情况下,我希望能够将环境设置为固定值。否则,我希望启用用户手动选择环境。 请注意,像每个环境的EndPoints一些环境设置是定义一个预定义的XML文件。

更新(可能的解决方案)
@albciff

在从ReadyAPI(1.9.0)的最新版本,像你描述这不起作用。

  • testrunner.bat返回SoapUIProTestCaseRunner
  • 通过UI运行返回InProcessSoapUIProTestCaseRunner

当使用此代码: def runner = com.eviware.soapui.SoapUI.getCmdLineRunner(); log.info "runner = [" + runner.getClass().getSimpleName() + "]"

+0

请你详细说明你的使用情况?你想在哪里找到这些信息,以及这将如何帮助? testrunner只是执行测试的实用程序。但UI不一定用于执行,可用于设计测试。 – Rao

回答

0

我认为这里面有没有SOAPUI属性之间它是如何的差执行。实际上我测试你的建议:

def env = testRunner.testCase.testSuite.project.activeEnvironment.name 

,并返回Default这两种情况下(从UI和使用testrunner)。

一个可能的解决方法是这样做的,例如在testrunner执行的CLI中传递一个项目属性参数;然后在您的代码中检查此参数以检测项目的启动方式。

要传递一个项目属性,您必须使用-Pname=value。因此,例如使用启动testrunner

testrunner -r -I <path/To/yourProject.xml> -PrunningBy=testRunner 

然后在你的代码,你可以得到的财产,检查这个内容,如果它是由testrunner或从UI运行来决定的,是这样的:

def runningBy = testRunner.testCase.testSuite.project.getPropertyValue('runningBy') 

if(runningBy){ 
    // it's not null so is launched from testRunner 
}else{ 
    // it's null, so is launched from UI 
} 

UPDATE

后审查API似乎有可能想到的方法如下:

com.eviware.soapui.SoapUI.getCmdLineRunner() 

它从UI执行时返回null,而是从testrunner执行它返回并且com.eviware.soapui.tools.CmdLineRunner的实例。

所以,你可以使用类似:

def clr = com.eviware.soapui.SoapUI.getCmdLineRunner() 

if(clr){ 
    // it's not null so is launched from testRunner 
}else{ 
    // it's null, so is launched from UI 
} 
+0

谢谢,但这不适用于我的ReadyAPI版本,请参阅我的更新评论。你能仔细检查一下吗? –

1

一个更简单的方法来检测,这将是:

if (com.eviware.soapui.SoapUI.isCommandLine()) { 
    // todo 
} 

找到在community.smartbear.com

相关问题