Skip to content

Commit

Permalink
Documentation for Moon commit cc899d8cca543bdc99ca446ff9903f9dcadf6a06
Browse files Browse the repository at this point in the history
  • Loading branch information
aerokube/moon2 committed Apr 27, 2023
1 parent f626231 commit ec34560
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion latest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ <h1>Moon</h1>
<li><a href="#selenium-locale">2.2.10. Changing Browser Locale</a></li>
<li><a href="#selenium-time-zone">2.2.11. Changing Browser Time Zone</a></li>
<li><a href="#selenium-external-host">2.2.12. Using External Hosts</a></li>
<li><a href="#selenium-proxy">2.2.13. Using Proxy Servers</a></li>
</ul>
</li>
<li><a href="#cypress">2.3. Using Cypress</a>
Expand Down Expand Up @@ -2814,6 +2815,71 @@ <h4 id="selenium-external-host"><a class="anchor" href="#selenium-external-host"
<p>With such configuration Selenium session requests with be randomly load-balanced across the hosts specified in <code>URLS</code> environment variable. VNC feature should also work - you should be seeing remote host screen in Moon UI.</p>
</div>
</div>
<div class="sect3">
<h4 id="selenium-proxy"><a class="anchor" href="#selenium-proxy"></a>2.2.13. Using Proxy Servers</h4>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Using proxy with username and password is available since Moon 2.5.0.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>In some cases you may need to configure launched browser to go through some proxy server. Selenium WebDriver protocol <a href="https://www.w3.org/TR/webdriver/#proxy">supports</a> standard capabilities to configure proxy server for any browser. For example:</p>
</div>
<div class="listingblock">
<div class="title">Configuring proxy settings for a browser with raw capabilities</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">ChromeOptions options = <span class="keyword">new</span> ChromeOptions();
<span class="predefined-type">String</span> proxyHost = <span class="string"><span class="delimiter">&quot;</span><span class="content">proxy.example.com:3128</span><span class="delimiter">&quot;</span></span>;
capabilities.setCapability(<span class="string"><span class="delimiter">&quot;</span><span class="content">proxy</span><span class="delimiter">&quot;</span></span>, <span class="predefined-type">Map</span>.of(
<span class="string"><span class="delimiter">&quot;</span><span class="content">proxyType</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">manual</span><span class="delimiter">&quot;</span></span>,
<span class="string"><span class="delimiter">&quot;</span><span class="content">httpProxy</span><span class="delimiter">&quot;</span></span>, proxyHost,
<span class="string"><span class="delimiter">&quot;</span><span class="content">sslProxy</span><span class="delimiter">&quot;</span></span>, proxyHost,
));
WebDriver driver = <span class="keyword">new</span> RemoteWebDriver(<span class="keyword">new</span> <span class="predefined-type">URL</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">https://moon.example.com/wd/hub</span><span class="delimiter">&quot;</span></span>), options);</code></pre>
</div>
</div>
<div class="paragraph">
<p>For some programming languages there is a wrapper object called <code>Proxy</code> allowing to set the same value in more type-safe way:</p>
</div>
<div class="listingblock">
<div class="title">Configuring proxy settings for a browser with Proxy object</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">ChromeOptions options = <span class="keyword">new</span> ChromeOptions();
<span class="predefined-type">Proxy</span> proxy = <span class="keyword">new</span> <span class="predefined-type">Proxy</span>();
<span class="predefined-type">String</span> proxyHost = <span class="string"><span class="delimiter">&quot;</span><span class="content">proxy.example.com:3128</span><span class="delimiter">&quot;</span></span>;
proxy
.setProxyType(<span class="predefined-type">Proxy</span>.ProxyType.MANUAL)
.setHttpProxy(proxyHost)
.setSslProxy(proxyHost);
options.setProxy(proxy);
WebDriver driver = <span class="keyword">new</span> RemoteWebDriver(<span class="keyword">new</span> <span class="predefined-type">URL</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">https://moon.example.com/wd/hub</span><span class="delimiter">&quot;</span></span>), options);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Very often proxy servers require to provide username and password for authentication. While the majority of Selenium implementations don&#8217;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 (<code>username:password@host:port</code>):</p>
</div>
<div class="listingblock">
<div class="title">Configuring proxy settings with authentication</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">ChromeOptions options = <span class="keyword">new</span> ChromeOptions();
<span class="comment">// Note username:password on the line below</span>
<span class="predefined-type">String</span> proxyHost = <span class="string"><span class="delimiter">&quot;</span><span class="content">username:[email protected]:3128</span><span class="delimiter">&quot;</span></span>;
capabilities.setCapability(<span class="string"><span class="delimiter">&quot;</span><span class="content">proxy</span><span class="delimiter">&quot;</span></span>, <span class="predefined-type">Map</span>.of(
<span class="string"><span class="delimiter">&quot;</span><span class="content">proxyType</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">manual</span><span class="delimiter">&quot;</span></span>,
<span class="string"><span class="delimiter">&quot;</span><span class="content">httpProxy</span><span class="delimiter">&quot;</span></span>, proxyHost,
<span class="string"><span class="delimiter">&quot;</span><span class="content">sslProxy</span><span class="delimiter">&quot;</span></span>, proxyHost,
));
WebDriver driver = <span class="keyword">new</span> RemoteWebDriver(<span class="keyword">new</span> <span class="predefined-type">URL</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">https://moon.example.com/wd/hub</span><span class="delimiter">&quot;</span></span>), options);</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="cypress"><a class="anchor" href="#cypress"></a>2.3. Using Cypress</h3>
Expand Down Expand Up @@ -8030,7 +8096,7 @@ <h2 id="mobile-emulation-devices"><a class="anchor" href="#mobile-emulation-devi
<div id="footer">
<div id="footer-text">
Version latest<br>
Last updated 2023-04-27 01:54:25 UTC
Last updated 2023-04-27 09:33:00 UTC
</div>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand Down

0 comments on commit ec34560

Please sign in to comment.