Ask a Question

How to retrieve the active environment name in groovy script?

SOLVED
jays
Occasional Contributor

How to retrieve the active environment name in groovy script?

I need to set some variables based on the current active environment. How can I access the environment name in groovy script?

2 REPLIES 2
Radford
Super Contributor

The following code is from one of my test case startup scripts:

 

def activeEnviroment = testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName()
log.info('Active enviroment = ' + activeEnviroment)

 

 

You need to get hold of the project object as this is where most of the methods relating to environments are, depending where your Groovy script is it might be subtly different from the above.

 

Note: That getActiveEnvironmentName is implemented by a "Pro" class so the method doesn't show up in Ready API code completion (This limitation was raised with SmartBear issue API-957).

jays
Occasional Contributor

Thank you and that works! And here is what I found which works too.

 

testRunner.testCase.project.getActiveEnvironment().name

 

gives you the active environment name in Pro.

cancel
Showing results for 
Search instead for 
Did you mean: