1

Is it possible to determine if SoapUI (ReadyAPI) is started

  1. via testrunner.bat
  2. by the user (running in interactive UI-mode)

I know that you can retrieve the current environment using this groovy script code:

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

However I wonder what value this will return when running via the command-line (testrunner.bat) ; will it return the active environment from the test project, or will it be null/empty ?


Update (use-case)
The user case is that depending on the way the tests are run. In case of testrunner.bat I want to be able to set the environment to a fixed value. Else I want enable the user to select the environment manually. Note that the some environment settings like EndPoints for each environment are defined a pre-defined XML file.

Update (possible solution)
@albciff

On the latest version from ReadyAPI (1.9.0), this does not work as you described.

  • testrunner.bat returns SoapUIProTestCaseRunner
  • running via ui returns InProcessSoapUIProTestCaseRunner

When using this code: def runner = com.eviware.soapui.SoapUI.getCmdLineRunner(); log.info "runner = [" + runner.getClass().getSimpleName() + "]"

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
  • Would you please elaborate your use case? where do you want find that information and how that will help? testrunner is just utility to execute the tests. But UI is not necessarily for execution, can be used for designing the tests. – Rao Nov 24 '16 at 15:21

2 Answers2

2

A more easier way to detect this would be:

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

Found at community.smartbear.com

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
0

I think that there is no property inside SOAPUI to difference between how it's executed. In fact I test your proposal:

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

And it returns Default for both cases (from UI and using testrunner).

A possible workaround to do so, it's for example to pass a project property parameter in the CLI of the testrunner execution; and then in your code check for this parameter to detect how the project is launched.

To pass a project property you've to use -Pname=value. So for example launch the testrunner using:

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

And then in your code you can get the property and check for this content to decide if it's running by testrunner or from the UI, something like:

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

After reviewing the API seems that it's possible thought the follow method:

com.eviware.soapui.SoapUI.getCmdLineRunner()

It returns null when executed from UI, instead when executed from testrunner it returns and instance of com.eviware.soapui.tools.CmdLineRunner.

So you can use something like:

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
}
albciff
  • 18,112
  • 4
  • 64
  • 89
  • Thanks, but this does not work on my ReadyAPI version, see my updated comment. Can you please double check on this ? – Stef Heyenrath Nov 24 '16 at 12:15
  • in ReadyAPI version 2.7.0, it returns a com.smartbear.ready.cmd.runner.pro.**InProcessSoapUIProTestCaseRunner** instance when run from UI, and a com.smartbear.ready.cmd.runner.pro.**SoapUIProTestCaseRunner** when run with testRunner – A.Joly Jun 21 '19 at 06:26