Forum Discussion

WilliamU's avatar
WilliamU
New Contributor
11 years ago

Getting the TestRunner environement

I have a need to retrieve the value for the -E flag (-EProd, -EBeta, etc.) from within a groovy script. I'll start off by saying that
testSuite.project.getActiveEnvironment().getName()
does not give me the value. It gives me the value that the project file currently has saved, not the value TestRunner overrides with (which makes sense). I ran through your source and the "SoapUITestCaseRunner" class is what handles the cmd line parsing. It sets the environment to a private variable:
public void setEndpoint(String endpoint)
{
log.info( "setting test endpoint to [" + endpoint+ "]" );
this.endpoint = endpoint.trim();
}


There is unfortunately is no getter for this. So, from within a teardown script, how could I go about getting the value of this? I WOULD like to find it on some kind of project/suite/runner wide variable (i.e. runner.properties["endpoint"]). I would NOT like to have to access a particular testcase to get it (i.e. runner.testCase.properties["endpoint"]). Thank you!

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    The option you found in the source code is for setting the end-point, not the environment. The environment is set through the -E (capital E) option and is only available in SoapUI Pro (so you won't find it in the Open Source code).

    The correct way to get the active environment is as follows:

    - Create a project-level property called "activeEnv" or any name you want to describe the active environment.
    - Select each environment you have (open the relevant TestSuite) and set the value of the "activeEnv" property appropriately for each one.
    - In a Groovy script print the value of the active environment as follows:

    def activeEnv = context.expand( '${#Project#activeEnv}' )
    log.info "The active environment is $activeEnv"


    Regards,

    Renato
    SmartBear Software