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.