From ec34560e14a95664250948d66defef7bd37b6aa7 Mon Sep 17 00:00:00 2001 From: aerokube/moon2 Date: Thu, 27 Apr 2023 09:40:16 +0000 Subject: [PATCH] Documentation for Moon commit cc899d8cca543bdc99ca446ff9903f9dcadf6a06 --- latest/index.html | 68 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/latest/index.html b/latest/index.html index de77b69..a22aee2 100644 --- a/latest/index.html +++ b/latest/index.html @@ -591,6 +591,7 @@

Moon

  • 2.2.10. Changing Browser Locale
  • 2.2.11. Changing Browser Time Zone
  • 2.2.12. Using External Hosts
  • +
  • 2.2.13. Using Proxy Servers
  • 2.3. Using Cypress @@ -2814,6 +2815,71 @@

    With such configuration Selenium session requests with be randomly load-balanced across the hosts specified in URLS environment variable. VNC feature should also work - you should be seeing remote host screen in Moon UI.

    +
    +

    2.2.13. Using Proxy Servers

    +
    + + + + + +
    + + +Using proxy with username and password is available since Moon 2.5.0. +
    +
    +
    +

    In some cases you may need to configure launched browser to go through some proxy server. Selenium WebDriver protocol supports standard capabilities to configure proxy server for any browser. For example:

    +
    +
    +
    Configuring proxy settings for a browser with raw capabilities
    +
    +
    ChromeOptions options = new ChromeOptions();
    +String proxyHost = "proxy.example.com:3128";
    +capabilities.setCapability("proxy", Map.of(
    +    "proxyType", "manual",
    +    "httpProxy", proxyHost,
    +    "sslProxy", proxyHost,
    +));
    +WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    +
    +
    +
    +

    For some programming languages there is a wrapper object called Proxy allowing to set the same value in more type-safe way:

    +
    +
    +
    Configuring proxy settings for a browser with Proxy object
    +
    +
    ChromeOptions options = new ChromeOptions();
    +Proxy proxy = new Proxy();
    +String proxyHost = "proxy.example.com:3128";
    +proxy
    +    .setProxyType(Proxy.ProxyType.MANUAL)
    +    .setHttpProxy(proxyHost)
    +    .setSslProxy(proxyHost);
    +options.setProxy(proxy);
    +WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    +
    +
    +
    +

    Very often proxy servers require to provide username and password for authentication. While the majority of Selenium implementations don’t work with such proxy servers, Moon allows to configure authentication out of the box, using the same capabilities - simply add username and password to proxy host value (username:password@host:port):

    +
    +
    +
    Configuring proxy settings with authentication
    +
    +
    ChromeOptions options = new ChromeOptions();
    +// Note username:password on the line below
    +String proxyHost = "username:password@proxy.example.com:3128";
    +capabilities.setCapability("proxy", Map.of(
    +    "proxyType", "manual",
    +    "httpProxy", proxyHost,
    +    "sslProxy", proxyHost,
    +));
    +WebDriver driver = new RemoteWebDriver(new URL("https://moon.example.com/wd/hub"), options);
    +
    +
    +