Back to All Scenarios
Scenario 58 of 100
Framework Design
Advanced
Maintaining Separate Environments (QA, UAT, PROD)
πScenario Overview
Maintaining Separate Environments (QA, UAT, PROD)
Key Takeaways & Cheat Sheet
- βMaintain dedicated environment configuration files (.properties or .yml)
- βPass target environments dynamically via Maven execution parameters
- βBuild a secure ConfigReader to load credentials at test initialization
- βEnforce database profile switching matching selected web targets
Short Direct Answer
To run tests across multiple environments (QA, UAT, Production), keep configuration parameters isolated from the code. Create separate properties files (e.g., `qa.properties`, `uat.properties`) and use Maven/Gradle system variables (`-Denv=qa`) at run time. Build a configuration reader that loads the appropriate environment files dynamically based on this variable.
β οΈ Senior Warning (Red Flag)
Never hardcode credentials or endpoints inside your Page Objects or test files. If a configuration changes or you need to switch environments, you will have to modify dozens of source files.
π‘ STAR Deep Dive Explanation & Pro Tip
Always include default environment fail-safes (like falling back to QA when no system property is provided) to prevent developer tests from crashing locally.
SeleniumAutomation.java
Selenium 4 + Javaimport java.io.FileInputStream;
import java.util.Properties;
public class EnvironmentConfig {
private static Properties prop;
public static void loadProperties() {
prop = new Properties();
// Read "env" parameter passed from maven command line (defaults to qa)
String env = System.getProperty("env", "qa");
String filePath = "src/test/resources/config/" + env + ".properties";
try (FileInputStream fs = new FileInputStream(filePath)) {
prop.load(fs);
} catch (Exception e) {
throw new RuntimeException("Failed to load config properties for environment: " + env);
}
}
public static String getUrl() {
return prop.getProperty("baseUrl");
}
}
// Command execution: mvn test -Denv=uat