1

是否可以确定是否启动了 SoapUI (ReadyAPI)

  1. 通过 testrunner.bat
  2. 由用户(在交互式 UI 模式下运行)

我知道您可以使用以下 groovy 脚本代码检索当前环境:

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

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


更新(用例)
用户用例取决于测试的运行方式。如果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() + "]"

4

2 回答 2

2

一种更简单的检测方法是:

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

community.smartbear.com找到

于 2016-12-01T06:50:26.417 回答
0

我认为 SOAPUI 内部没有属性可以区分它的执行方式。事实上,我测试了你的建议:

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

它返回Default两种情况(从 UI 和 using testrunner)。

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

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

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

然后在您的代码中,您可以获得属性并检查此内容以确定它是由 UI 运行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
}

更新

在查看 API 之后,似乎可以考虑以下方法:

com.eviware.soapui.SoapUI.getCmdLineRunner()

null在从 UI 执行时返回,而不是从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
}
于 2016-11-24T10:45:11.967 回答