Answer
Configuration Management in Selenium Framework
config.properties
PROPERTIES
# src/test/resources/config/config.properties
# Browser
browser=chrome
headless=false
# Timeouts (seconds)
implicit.wait=10
explicit.wait=15
page.load.timeout=30
# URLs
base.url=https://staging.automateqa.online
api.base.url=https://api.staging.automateqa.online
# Test data
test.user.email=testuser@automateqa.com
test.user.password=Test@123
# Reports
report.dir=test-output/reports
screenshot.dir=test-output/screenshots
Environment-Specific Files
CODE
src/test/resources/config/
├── config.properties ← default (staging)
├── qa.properties ← QA environment
└── prod.properties ← production (read-only tests)
PROPERTIES
# qa.properties
base.url=https://qa.automateqa.online
test.user.email=qa_test@automateqa.com
ConfigReader — Singleton
Java
// config/ConfigReader.java
public class ConfigReader {
private static Properties properties;
// Singleton — load only once
private static Properties getProperties() {
if (properties == null) {
properties = new Properties();
// env can be passed via Maven: -Denv=qa
String env = System.getProperty("env", "config");
String path = "src/test/resources/config/" + env + ".properties";
try (FileInputStream fis = new FileInputStream(path)) {
properties.load(fis);
} catch (IOException e) {
throw new RuntimeException("Cannot load: " + path, e);
}
}
return properties;
}
// System properties override file values (great for CI/CD)
public static String get(String key) {
return System.getProperty(key, getProperties().getProperty(key));
}
public static int getInt(String key) {
return Integer.parseInt(get(key));
}
public static boolean getBoolean(String key) {
return Boolean.parseBoolean(get(key));
}
// Typed getters for common config
public static String getBrowser() { return get("browser"); }
public static String getBaseUrl() { return get("base.url"); }
public static boolean isHeadless() { return getBoolean("headless"); }
public static int getExplicitWait() { return getInt("explicit.wait"); }
}
Usage in Framework
Java
// DriverManager reads browser type from config
String browser = ConfigReader.getBrowser();
// BaseTest reads URL from config
driver.get(ConfigReader.getBaseUrl());
// Tests use credentials from config
loginPage.login(
ConfigReader.get("test.user.email"),
ConfigReader.get("test.user.password")
);
Override Config in CI/CD (Maven / GitHub Actions)
Bash
# Switch environment via Maven system property
mvn test -Denv=qa -Dbrowser=firefox -Dheadless=true
# In GitHub Actions
- run: mvn test
env:
# These override config.properties values
with:
# Pass as system property
- run: mvn test -Denv=qa -Dbase.url=${{ secrets.QA_URL }} -Dheadless=true
testng.xml — Pass Parameters to Tests
XML
<suite name="Automation Suite">
<parameter name="browser" value="chrome"/>
<parameter name="env" value="staging"/>
<test name="Smoke Tests">
<classes>
<class name="com.automateqa.tests.LoginTest"/>
</classes>
</test>
</suite>
Java
// Read TestNG parameter in BaseTest
@Parameters({"browser", "env"})
@BeforeMethod
public void setUp(@Optional("chrome") String browser,
@Optional("staging") String env) {
System.setProperty("browser", browser);
System.setProperty("env", env);
DriverManager.init();
}
