Changing environment in Jenkins mid-test
I have a ReadyAPI suite with three test cases.
- First is a test case to pull all the needed data using data sources.
- Then a test case that runs some SOAP requests.
- The next test case has a first step to change the environment using a groovy script. The following test steps are the same as the second test case, so we can compare the responses between two environments with same data from the first test case.
The problem I'm seeing is that in the ReadyAPI application it works great. In Jenkins (using testrunner), the environment endpoints don't change like they do in the ReadyAPI app after the groovy script environment change.
Here's the groovy script that works fine in the ReadyAPI application. And, in the Jenkins console log it outputs what I expect, but the test steps that follow continue to use the original environment set in the testrunner command line with the -E LOCAL.
//To get the active Environment from, example "LOCAL"
def env = testRunner.testCase.testSuite.project.getActiveEnvironment().getName()
log.info("Active Environment was: " + env)
//To change the active Environment to, example "CLOUD"
env = testRunner.testCase.testSuite.project.getEnvironmentByName("CLOUD");
testRunner.testCase.testSuite.project.setActiveEnvironment(env)
log.info("Active Environment now: " + testRunner.testCase.testSuite.project.getActiveEnvironment().getName())
Do I have to go outside the test files (groovy script saved in the project) to set the environment like I do initially to set the environment "-E LOCAL" command for testrunner? If so, what's the syntax on that?