Forum Discussion

jays's avatar
jays
Occasional Contributor
8 years ago
Solved

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?

  • jays's avatar
    jays
    8 years ago

    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.

2 Replies

  • Radford's avatar
    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's avatar
      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.