Introduction
Configuration management helps keep test settings organized and easy to change. It makes tests flexible and reusable.
Configuration management helps keep test settings organized and easy to change. It makes tests flexible and reusable.
public class Config { public static final String BASE_URL = "https://example.com"; public static final String BROWSER = "chrome"; public static final int TIMEOUT = 10; }
public class Config { public static final String BASE_URL = "https://testsite.com"; public static final String BROWSER = "firefox"; }
Properties props = new Properties(); try (FileInputStream fis = new FileInputStream("config.properties")) { props.load(fis); } String url = props.getProperty("baseUrl");
This test uses configuration to choose the browser and URL. It opens the page and prints the title.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; class Config { public static final String BASE_URL = "https://example.com"; public static final String BROWSER = "chrome"; } public class TestLogin { public static void main(String[] args) { WebDriver driver; switch (Config.BROWSER.toLowerCase()) { case "chrome": driver = new ChromeDriver(); break; case "firefox": driver = new FirefoxDriver(); break; default: throw new IllegalArgumentException("Unsupported browser: " + Config.BROWSER); } driver.get(Config.BASE_URL); System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } }
Always keep sensitive data like passwords out of code and use secure storage.
Use descriptive names for configuration keys to avoid confusion.
Test configuration changes carefully to avoid breaking tests.
Configuration management separates settings from test code.
It makes tests easier to maintain and run in different environments.
Use constants or external files to store configuration values.
public class Config {
public static final String ENV = "staging";
public static final String URL = ENV.equals("production") ? "https://prod.example.com" : "https://staging.example.com";
public static void main(String[] args) {
System.out.println(URL);
}
}public class Config {
public static final String BASE_URL = https://example.com;
}Pass the test and this pattern moves unknown