Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
8 years ago

Iterate over all available environments

I would like to loop through all of my available environments. We use a load balancer in front of 2 jvm nodes. It would be ideal to be able to run against all 3 end points during a test run. I have a script that accomplishes this but I will have to make an update any time a new environment was introduced (Say we want 3 jvm's in the future).

 

Does anyone know how to get a list of all environments available in a project? I have tried searching the community and online and can't seem to find much help other than getting the active environment, which doesn't really help me.

 

Here is the script I am currently using

 

//Enable any disabled steps
testRunner.testCase.testStepList.each {
 if (it.disabled) log.info "Enabling testCase: " + it.name
 testRunner.testCase.testSteps[it.name].setDisabled(false)
}

//Iterate through map, set end point and run all steps after current step
def map = [env01: 'test01', env02: 'test02']
for (item in map) {
 testRunner.testCase.testSuite.project.setActiveEnvironment(item.value)
 log.info "ENVIRONMENT SET TO " + item.value
 def testStepList = testRunner.testCase.testStepList
 def currentStepLabel = context.currentStep.label
 def currentStepIndex = testRunner.testCase.getTestStepIndexByName(currentStepLabel)
 for (testSteps in testStepList) {
  stepIndex = testRunner.testCase.getTestStepIndexByName(testSteps.name)
  if (stepIndex > currentStepIndex) {
   log.info "RUNNING TEST STEP " + "[ " + testSteps.name + " ]" + " WITH " + "[ " + currentStepLabel + " ]"
   testRunner.runTestStepByName(testSteps.name)
  }
 }
}

//Disable all steps after current step
def currentStepLabel = context.currentStep.label
def currentStepIndex = testRunner.testCase.getTestStepIndexByName(currentStepLabel)
def testStepList = testRunner.testCase.getTestStepList()
for (testSteps in testStepList) {
 def stepIndex = testRunner.testCase.getTestStepIndexByName(testSteps.name)
 if (stepIndex > currentStepIndex) {
  testRunner.testCase.testSteps[testSteps.name].setDisabled(true)
 }
}

 

I have a test case with a groovy step that has this code in it and then a soap request after it. This will loop through the environments but it would be better if I didn't have to maintain the environment list in this script itself.

 

 

  • The environment classes are part of the "Pro" functionality, and doesn't show up in the code completion options (I've logged this with SmartBear and it's now enhancement request API-957).

     

    You get the environment details from the WsdlProjectPro object, see sample code below:

     

    // Get the current active environment
    log.info(testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName()) 
    
    // Loop through each of the environments
    testRunner.getTestCase().getTestSuite().getProject().getEnvironmentList().each{ environment -> 
    	log.info(environment.getName())
    }
  • Radford's avatar
    Radford
    Super Contributor

    The environment classes are part of the "Pro" functionality, and doesn't show up in the code completion options (I've logged this with SmartBear and it's now enhancement request API-957).

     

    You get the environment details from the WsdlProjectPro object, see sample code below:

     

    // Get the current active environment
    log.info(testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName()) 
    
    // Loop through each of the environments
    testRunner.getTestCase().getTestSuite().getProject().getEnvironmentList().each{ environment -> 
    	log.info(environment.getName())
    }
    • jkrier's avatar
      jkrier
      Regular Contributor

      Thanks Radford, that's just what I needed.