Geolocation and Network Emulation

Faking the User's Location

ShopEase shows delivery dates by city. Test Bengaluru and Delhi without travelling, using a CDP command on Chromium browsers. executeCdpCommand takes plain maps, so it does not depend on version-specific classes.

ChromeOptions options = new ChromeOptions();
options.addArguments("--use-fake-ui-for-media-stream");     // auto-allow permission prompts
ChromeDriver driver = new ChromeDriver(options);

driver.executeCdpCommand("Browser.grantPermissions", Map.of(
        "origin", "https://shopease.example.com", "permissions", List.of("geolocation")));
driver.executeCdpCommand("Emulation.setGeolocationOverride", Map.of(
        "latitude", 12.9716, "longitude", 77.5946, "accuracy", 100));   // Bengaluru

driver.get("https://shopease.example.com/products/boat-rockerz-450");
System.out.println(driver.findElement(By.id("delivery-info")).getText());

Example

mvn test -Dtest=DeliveryByCityTest

Example output

Delivering to Bengaluru 560001 - Get it by Tomorrow
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Slow 3G Network

driver.executeCdpCommand("Network.enable", Map.of());
driver.executeCdpCommand("Network.emulateNetworkConditions", Map.of(
        "offline", false,
        "latency", 400,                       // ms
        "downloadThroughput", 50 * 1024,      // bytes per second (~400 kbps)
        "uploadThroughput", 20 * 1024));

long start = System.currentTimeMillis();
driver.get("https://shopease.example.com");
System.out.println("Home page on slow 3G: " + (System.currentTimeMillis() - start) + " ms");

Tip: Use network emulation to check that spinners, skeleton screens and timeouts behave well for users on slow mobile data, a big share of Indian traffic.