diff --git a/latest/index.html b/latest/index.html index 0b8a898..7aad4cc 100644 --- a/latest/index.html +++ b/latest/index.html @@ -587,7 +587,8 @@

Moon

  • 2.1.7. Accessing Files Downloaded with Browser
  • 2.1.8. Accessing Developer Tools
  • 2.1.9. Changing Browser Locale
  • -
  • 2.1.10. Using External Hosts
  • +
  • 2.1.10. Changing Browser Time Zone
  • +
  • 2.1.11. Using External Hosts
  • 2.2. Using Cypress @@ -2495,14 +2496,76 @@
    ChromeOptions options = new ChromeOptions();
     options.setCapability("browserVersion", "81.0");
    -options.setCapability("env", Arrays.asList("LANG=de_AT.UTF-8", "LANGUAGE=at:de", "LC_ALL=de_AT.UTF-8"));
    +capabilities.setCapability("moon:options", Map.of(
    +    "env", Arrays.asList("LANG=de_AT.UTF-8", "LANGUAGE=at:de", "LC_ALL=de_AT.UTF-8")
    +));
     WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    -

    2.1.10. Using External Hosts

    +

    2.1.10. Changing Browser Time Zone

    +
    +

    A common testing task is checking that your web application behaves as expected in different time zones. Depending on tested web application one of the following approaches can help.

    +
    +
    +
    Option 1: Setting TZ environment variable
    +
    +

    A typical approach for overriding time zone in Linux is setting TZ environment variable. To do this in Moon - you just need to set env capability in your code:

    +
    +
    +
    +
    ChromeOptions options = new ChromeOptions();
    +
    +capabilities.setCapability("moon:options", Map.of(
    +    "env", Arrays.asList("TZ=America/New_York") // This is where you set TZ variable with values like "America/New_York" or "Europe/London"
    +));
    +
    +WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    +
    +driver.get("https://dateful.com/time-zone-converter"); // An example web site that respects TZ setting
    +
    +
    +
    +

    When you set time zone like this, web application can fetch your time zone information using Javascript Time API. The main problem with this approach is that not all web applications are using it. So if it does not work - then try the next option.

    +
    +
    +
    +
    Option 2: Overriding Browser Geolocation
    +
    +

    Some web applications are applying time zone settings by analyzing browser geolocation information using Javascript Geolocation API. If setting time zone directly does not work, you may try to override geolocation API coordinates:

    +
    +
    +
    +
    ChromeOptions options = new ChromeOptions();
    +WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    +driver = new Augmenter().augment(driver);
    +
    +DevTools devTools = ((HasDevTools) driver).getDevTools();
    +devTools.createSession();
    +
    +// Location of London (change this to 40.715502419712244, -74.00597334074466 for New York)
    +devTools.send(Emulation.setGeolocationOverride(Optional.of(51.495930861102245),
    +        Optional.of(0.010205721644136127),
    +        Optional.of(1)));
    +
    +driver.get("https://google.com");
    +WebElement element = driver.findElement(By.name("q"));
    +Actions actionProvider = new Actions(driver);
    +Action select = actionProvider
    +        .sendKeys("what is my time zone\n")
    +        .build();
    +select.perform();
    +
    +
    +
    +

    In some rare cases when both options do not work, this can be a signal that your web application is detecting your time zone by comparing your IP address with IP addresses geolocation database. In that case you may need to configure your browser to go through a proxy server physically located in desired geographic region.

    +
    +
    +
    +
    +

    2.1.11. Using External Hosts

    Moon expects to run the majority of browsers in pods inside Kubernetes or Openshift cluster. However sometimes you may need to run Selenium tests on some external hosts: hardware servers or virtual machines. Mainly this could be needed in two situations:

    @@ -7462,7 +7525,7 @@