0

For now I have a config.properties file and a singleton configuration object, which reads the file to a map and then puts all the system variables there as well. So when I run my tests via Jenkins, job's parameters with the same name will override values, set in config.properties file.

This is expected and correct behavior for me. But I'd like to keep all the configuration and build parameters in GebConfig.groovy file.

So two questions here:

  1. Now, if I need to get GebConfig property in my code, I use browser.getConfig().getRawConfig().get("contextPath"). Is it proper call or there is better way to get params from config in tests' code?

  2. How to implement passing Jenkins job's parameters to Geb configuration? I got only the idea to search for it in System.getenv() first:

    public String getProperty(String name) {
        Map<String, String> systemEnv = System.getenv();
        return systemEnv.get(name) ?: browser.config.rawConfig.get(name);
    }
    
Bohdan Nesteruk
  • 794
  • 17
  • 42

1 Answers1

1

All build tools accept -DvarName=varValue to pass properties into GebConfig. Gradle, Maven, and Ant. So you'd pass that variable through in your Jenkins Build step

Edit: Below is in my GebConfig which handles default values vs passed in variables

System.setProperty("geb.env.username", System.getProperty("geb.env.username", 'test'))
Doug Clark
  • 332
  • 5
  • 21
  • Yes, but as far as I know, after passing a property via -DvarName=varValue I will need to describe it in duild gradle by calling systemProperty("varName", project.varName). And then I am able to use it in GebConfig as System.getProperty("varName"). My question is how to replace the value of varName in GebConfig automatically if it was passed via -D parameter or exists in System.getEnv() – Bohdan Nesteruk Nov 14 '18 at 09:50