Selenium + Java · Lesson 11 of 44

0/44 done

Module 11: Java for Automation

11. Enterprise Java Design Patterns for Test Automation

16 minlesson

Your 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".

Write it in the editor, then press Check answer (Ctrl + Enter).

Enums for Type-Safe Automation

Avoid passing error-prone raw strings like "chrome" or "prod".

java
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; }
}

Key Takeaways & Walkthrough Summary

Welcome to Phase 2! In this module, we connect Java directly to automation architecture. You will learn to build reusable helper methods, type-safe enums for browsers and environments, and structured configuration handlers. Let's design maintainable automation code!

Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why use enums instead of public static final String constants?

Enums enforce compile-time type safety so developers cannot pass arbitrary invalid strings into test configuration methods.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Java
Skip