确定是通过testrunner.bat还是由用户(在UI模式下运行)启动SoapUI(ReadyAPI)

时间:2016-11-24 09:28:59

标签: batch-file groovy soapui environment ready-api

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

  1. 通过testrunner.bat
  2. 由用户(以交互式UI模式运行)
  3. 我知道你可以使用这个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() + "]"

2 个答案:

答案 0 :(得分:1)

更容易检测到这种情况的方法是:

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

找到community.smartbear.com

答案 1 :(得分: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
}

<强>更新

在审核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
}
相关问题