Latest post from this blog

How to Manage Test Execution Across Different Browsers and Environments (QA, UAT, Staging)

In real-time automation projects, test execution is never limited to a single browser or a single environment.

Applications must be validated across multiple browsers (Chrome, Firefox, Edge) and multiple environments such as QA, UAT, and Staging before going live.

A well-designed Selenium + Java + Cucumber automation framework should allow testers to switch browsers and environments easily without changing test scripts.

This blog explains how to manage test execution efficiently across different browsers and environments using best practices followed in real projects.


Why Multi-Browser and Multi-Environment Testing Is Important

  • Different users use different browsers

  • QA, UAT, and Staging environments have different configurations

  • Bugs may appear only in specific environments or browsers

  • Same test cases must be validated everywhere before production release


Common Challenges Testers Face

  • Hardcoded browser names and URLs

  • Maintaining separate test scripts for each environment

  • Browser-specific failures

  • Difficulty running tests from CI/CD tools

  • Data conflicts during parallel execution


Best Practices to Manage Browser and Environment Execution

1. Use Configuration Files (Properties File)

The most common and recommended approach is using a configuration file to control execution.

Example: config.properties

browser=chrome
environment=qa

qa.url=https://qa.example.com
uat.url=https://uat.example.com
staging.url=https://staging.example.com

👉 This allows you to change the browser or environment without modifying the test code.


2. Read Configuration Values Dynamically

Create a utility class to read values from the configuration file.

public class ConfigReader {

    private static Properties properties;

    static {
        try {
            FileInputStream fis = new FileInputStream("config.properties");
            properties = new Properties();
            properties.load(fis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getProperty(String key) {
        return properties.getProperty(key);
    }
}

3. Browser Selection in a Central Place

Browser initialization should be handled in a Base class or Hooks class, not inside test steps.

public WebDriver initializeDriver() {

    String browser = ConfigReader.getProperty("browser");

    if (browser.equalsIgnoreCase("chrome")) {
        driver = new ChromeDriver();
    } else if (browser.equalsIgnoreCase("firefox")) {
        driver = new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("edge")) {
        driver = new EdgeDriver();
    }

    driver.manage().window().maximize();
    return driver;
}

This ensures:

  • Clean framework design

  • Easy browser switching


4. Environment-Based URL Handling

Instead of hardcoding URLs, select them based on the environment.

public String getApplicationUrl() {

    String env = ConfigReader.getProperty("environment");

    if (env.equalsIgnoreCase("qa")) {
        return ConfigReader.getProperty("qa.url");
    } else if (env.equalsIgnoreCase("uat")) {
        return ConfigReader.getProperty("uat.url");
    } else {
        return ConfigReader.getProperty("staging.url");
    }
}

👉 The same test cases run across all environments without duplication.


5. Override Values Using Maven Command Line

Maven allows you to change browser and environment during execution.

mvn test -Dbrowser=firefox -Denvironment=uat

Update your code to read system properties first:

String browser = System.getProperty("browser",
        ConfigReader.getProperty("browser"));

String environment = System.getProperty("environment",
        ConfigReader.getProperty("environment"));

6. Parallel Execution Support

To support parallel execution:

  • Use ThreadLocal WebDriver

  • Avoid static variables

  • Use scenario-level data sharing (StepData/TestContext)

Benefits:

  • Faster execution

  • Reliable cross-browser testing

  • Better CI/CD performance


7. CI/CD Integration (Jenkins Example)

In CI/CD pipelines:

  • Browser and environment are added as parameters

  • Passed to Maven during build execution

mvn clean test -Dbrowser=${BROWSER} -Denvironment=${ENV}

This makes test execution:

  • Fully automated

  • Repeatable

  • Environment-independent


Real-Time Execution Flow

  1. Select browser and environment

  2. Read values from config or system properties

  3. Initialize WebDriver

  4. Launch environment-specific URL

  5. Execute test cases

  6. Generate reports


Summary

A scalable Selenium automation framework manages execution across browsers and environments by:

  • Using configuration files

  • Supporting dynamic browser and environment selection

  • Avoiding hardcoded values

  • Integrating with Maven and CI/CD pipelines

  • Supporting parallel execution

This approach ensures flexibility, maintainability, and reliability in real-time automation projects.


Conclusion

Managing test execution across multiple browsers and environments is a critical requirement in modern automation frameworks.

By following the practices explained above, testers can build a robust, scalable, and production-ready automation framework.

Comments

Popular posts from this blog

Purpose of the StepData Class in Selenium + Java Cucumber Automation Framework

Ensuring Thread Safety in Parallel Test Execution with Selenium, Cucumber, and Java