I’ve recently been experimenting with GEB, which is a selenium framework that uses the groovy language. One of first challenges I encountered was trying to switch between multiple environments, instances, subdomains, or base urls. GEB uses a config file called GebConfig.groovy that is a standard groovy configuration file. This file is read by the ConfigSlurper class. The ConfigSlurper takes in different environments in the constructer. I also wanted to be able to switch environments based on a command line overwrite – either ANT or Gradle. The following is a small example on how to setup multiple environments that can be changed by a command line override.
[groovy]
def user = ""
def pass = ""
environment = System.getProperty("test.env", "example1")
switch(environment) {
case "example1":
user = "foo1"
pass = "foo2"
baseurl = "example1.zaphinath.com"
break
}
[/groovy]
The command line override in this case would be:
[bash]
gradle -Dtest.env=example1
[/bash]