Careeroza
Config Reader and Utilities
Environment Config Files
Example
Keep URLs, browsers and timeouts out of code:
src/test/resources/config/qa.properties
baseUrl=https://qa.shopease.example.com
browser=chrome
headless=false
explicitWait=10
[email protected]public final class ConfigReader {
private static final Properties PROPS = new Properties();
static {
String env = System.getProperty("env", "qa"); // mvn test -Denv=staging
String file = "/config/" + env + ".properties";
try (InputStream in = ConfigReader.class.getResourceAsStream(file)) {
PROPS.load(in);
} catch (IOException | NullPointerException e) {
throw new IllegalStateException("Cannot load " + file, e);
}
}
public static String get(String key) {
return System.getProperty(key, PROPS.getProperty(key)); // -Dkey=value wins
}
public static boolean getBoolean(String key) { return Boolean.parseBoolean(get(key)); }
public static int getInt(String key) { return Integer.parseInt(get(key)); }
}Runnable Config Reader
Example
The same logic with the file content in a text block. A command-line override (-Dheadless=true) is simulated with System.setProperty:
import java.io.*;
import java.util.*;
public class Main {
static final Properties PROPS = new Properties();
static String get(String key) { return System.getProperty(key, PROPS.getProperty(key)); }
public static void main(String[] args) throws IOException {
String qaFile = """
baseUrl=https://qa.shopease.example.com
browser=chrome
headless=false
explicitWait=10
""";
PROPS.load(new StringReader(qaFile));
System.setProperty("headless", "true"); // like mvn test -Dheadless=true on CI
for (String key : List.of("baseUrl", "browser", "headless", "explicitWait")) {
System.out.println(key + " = " + get(key));
}
int wait = Integer.parseInt(get("explicitWait"));
System.out.println("Explicit wait in ms: " + wait * 1000);
}
}Output
baseUrl = https://qa.shopease.example.com browser = chrome headless = true explicitWait = 10 Explicit wait in ms: 10000
Test Data Utilities
Example
Registration tests need a new email every run. A fixed timestamp keeps this output stable; in a real framework use System.currentTimeMillis() or a UUID:
import java.time.*;
import java.time.format.*;
import java.util.concurrent.atomic.*;
public class Main {
static final AtomicInteger COUNTER = new AtomicInteger();
static String uniqueEmail(String prefix, LocalDateTime now) {
String stamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
return prefix + "+" + stamp + "_" + COUNTER.incrementAndGet() + "@test.shopease.in";
}
static String indianMobile(int seed) {
return "9" + String.format("%09d", (seed * 7919L) % 1_000_000_000L);
}
public static void main(String[] args) {
LocalDateTime runTime = LocalDateTime.of(2026, 3, 14, 10, 30, 5);
for (int i = 1; i <= 3; i++) {
System.out.println(uniqueEmail("asha", runTime) + " " + indianMobile(i * 12345));
}
}
}Output
[email protected] 9097760055 [email protected] 9195520110 [email protected] 9293280165