πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
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 + Java
import 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