Careeroza
Properties Files for Config
config.properties
Configuration (URL, browser, timeouts) is different from test data. It goes into a .properties file so the same tests run against QA, staging or production-like environments without code changes.
Example
src/test/resources/config.properties
base.url=https://qa.shopease.example.com
browser=chrome
headless=false
explicit.wait.seconds=10
[email protected]Reading It
Example
java.util.Properties reads the file; a system property (-Dbrowser=firefox) can override a value. Here the file content comes from a string:
import java.io.StringReader;
import java.util.Properties;
public class Main {
public static void main(String[] args) throws Exception {
String file = """
base.url=https://qa.shopease.example.com
browser=chrome
explicit.wait.seconds=10
""";
Properties config = new Properties();
config.load(new StringReader(file));
System.setProperty("browser", "firefox"); // as if run with mvn test -Dbrowser=firefox
String browser = System.getProperty("browser", config.getProperty("browser"));
int wait = Integer.parseInt(config.getProperty("explicit.wait.seconds"));
String retries = config.getProperty("retry.count", "0"); // default when missing
System.out.println("URL: " + config.getProperty("base.url"));
System.out.println("Browser: " + browser + " (file says " + config.getProperty("browser") + ")");
System.out.println("Wait: " + wait + "s, retries: " + retries);
}
}Output
URL: https://qa.shopease.example.com Browser: firefox (file says chrome) Wait: 10s, retries: 0
Tip: Never commit real passwords in properties files. Read secrets from environment variables or the CI tool's secret store.