11. Enterprise Java Design Patterns for Test Automation

Enums for Type-Safe Automation

Avoid passing error-prone raw strings like "chrome" or "prod".
public enum BrowserType {
    CHROMIUM("chromium"),
    FIREFOX("firefox"),
    WEBKIT("webkit");

private final String value;
BrowserType(String value) { this.value = value; }
public String getValue() { return value; }
}

public enum Environment {
DEV("https://dev.targetqa.com"),
STAGING("https://staging.targetqa.com"),
PROD("https://targetqa.com");

private final String url;
Environment(String url) { this.url = url; }
public String getUrl() { return url; }
}

Task

  • Implement EnvironmentConfig:
  • 1. Create an enum Environment with values QA, STAGING, PROD.
  • 2. Implement getBaseUrl(Environment env) that returns corresponding URLs:
  • - QA -> "https://qa.targetqa.com"
  • - STAGING -> "https://staging.targetqa.com"
  • - PROD -> "https://targetqa.com".
πŸ’‘Common doubts
Did you like the problem?
Lesson 11 of 38
Java
Loading code editor…
Next