selenium-webdriver
Version:
The official WebDriver JavaScript bindings from the Selenium project
138 lines • 20.3 kB
HTML
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"><meta http-equiv="Content-Language" content="en"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Builder</title><link href="dossier.css" rel="stylesheet" type="text/css"><header><div><form><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></header><main><article><div class="parentlink"><b>Module:</b> <a href="module_selenium-webdriver_builder.html">selenium-webdriver/builder</a></div><div class="codelink"><a href="source/builder.js.src.html#l496">View Source</a></div><h1>class Builder</h1><p>Creates new <a href="class_webdriver_WebDriver.html"><code>WebDriver</code></a> instances. The environment
variables listed below may be used to override a builder's configuration,
allowing quick runtime changes.</p>
<ul><li>
<p><code>SELENIUM_BROWSER</code>: defines the target browser in the form
<code>browser[:version][:platform]</code>.</p>
</li><li>
<p><code>SELENIUM_REMOTE_URL</code>: defines the remote URL for all builder
instances. This environment variable should be set to a fully qualified
URL for a WebDriver server (e.g. http://localhost:4444/wd/hub). This
option always takes precedence over <code>SELENIUM_SERVER_JAR</code>.</p>
</li><li>
<p><code>SELENIUM_SERVER_JAR</code>: defines the path to the
<a href="http://selenium-release.storage.googleapis.com/index.html">
standalone Selenium server</a> jar to use. The server will be started the
first time a WebDriver instance and be killed when the process exits.</p>
</li></ul>
<p>Suppose you had mytest.js that created WebDriver with</p>
<pre><code>var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
</code></pre>
<p>This test could be made to use Firefox on the local machine by running with
<code>SELENIUM_BROWSER=firefox node mytest.js</code>. Rather than change the code to
target Google Chrome on a remote machine, you can simply set the
<code>SELENIUM_BROWSER</code> and <code>SELENIUM_REMOTE_URL</code> environment variables:</p>
<pre><code>SELENIUM_BROWSER=chrome:36:LINUX \
SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \
node mytest.js
</code></pre>
<p>You could also use a local copy of the standalone Selenium server:</p>
<pre><code>SELENIUM_BROWSER=chrome:36:LINUX \
SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \
node mytest.js
</code></pre>
<h3>new Builder()</h3><div><div class="fn-details"><div><b>Parameters</b></div><dl><dd>None.</dl></div></div><h2>Instance Methods</h2><div id="build" class="function"><div><h3>build()<span class="codelink"><a href="source/builder.js.src.html#l391">code »</a></span></h3><p>Creates a new WebDriver client based on this builder's current
configuration.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_WebDriver.html">webdriver.WebDriver</a></code><dd><p>A new WebDriver instance.</p>
</dl></div><div class="fn-details"><div><b>Throws</b></div><dl><dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a></code><dd><p>If the current configuration is invalid.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="disableEnvironmentOverrides" class="function"><div><h3>disableEnvironmentOverrides()<span class="codelink"><a href="source/builder.js.src.html#l130">code »</a></span></h3><p>Configures this builder to ignore any environment variable overrides and to
only use the configuration specified through this instance's API.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="forBrowser" class="function"><div><h3>forBrowser(<wbr>name, opt_version, opt_platform)<span class="codelink"><a href="source/builder.js.src.html#l225">code »</a></span></h3><p>Configures the target browser for clients created by this instance.
Any calls to <a href="module_selenium-webdriver_builder_class_Builder.html#withCapabilities"><code>#withCapabilities</code></a> after this function will
overwrite these settings.</p>
<p>You may also define the target browser using the <code>SELENIUM_BROWSER</code>
environment variable. If set, this environment variable should be of the
form <code>browser[:[version][:platform]]</code>.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>name<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The name of the target browser;
common defaults are available on the <a href="enum_webdriver_Browser.html"><code>webdriver.Browser</code></a> enum.</p>
<dt>opt_version<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A desired version; may be omitted if any
version should be used.</p>
<dt>opt_platform<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>The desired platform; may be omitted if any
version may be used.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getCapabilities" class="function"><div><h3>getCapabilities()<span class="codelink"><a href="source/builder.js.src.html#l203">code »</a></span></h3><p>Returns the base set of capabilities this instance is currently configured
to use.</p>
<div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_Capabilities.html">webdriver.Capabilities</a></code><dd><p>The current capabilities for this builder.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getServerUrl" class="function"><div><h3>getServerUrl()<span class="codelink"><a href="source/builder.js.src.html#l157">code »</a></span></h3><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The URL of the WebDriver server this instance is configured
to use.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="getWebDriverProxy" class="function"><div><h3>getWebDriverProxy()<span class="codelink"><a href="source/builder.js.src.html#l180">code »</a></span></h3><div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The URL of the proxy server to use for the WebDriver's HTTP
connections.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setAlertBehavior" class="function"><div><h3>setAlertBehavior(<wbr>beahvior)<span class="codelink"><a href="source/builder.js.src.html#l289">code »</a></span></h3><p>Sets the default action to take with an unexpected alert before returning
an error.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>beahvior<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The desired behavior; should be "accept", "dismiss",
or "ignore". Defaults to "dismiss".</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setChromeOptions" class="function"><div><h3>setChromeOptions(<wbr>options)<span class="codelink"><a href="source/builder.js.src.html#l304">code »</a></span></h3><p>Sets Chrome specific <a href="module_selenium-webdriver_chrome_class_Options.html">options</a>
for drivers created by this builder. Any logging or proxy settings defined
on the given options will take precedence over those set through
<a href="module_selenium-webdriver_builder_class_Builder.html#setLoggingPrefs"><code>#setLoggingPrefs</code></a> and <a href="module_selenium-webdriver_builder_class_Builder.html#setProxy"><code>#setProxy</code></a>, respectively.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>options<code>chrome.Options</code><dd><p>The ChromeDriver options to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setControlFlow" class="function"><div><h3>setControlFlow(<wbr>flow)<span class="codelink"><a href="source/builder.js.src.html#l378">code »</a></span></h3><p>Sets the control flow that created drivers should execute actions in. If
the flow is never set, or is set to <code>null</code>, it will use the active
flow at the time <a href="module_selenium-webdriver_builder_class_Builder.html#build"><code>#build()</code></a> is called.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>flow<code><a href="class_webdriver_promise_ControlFlow.html">webdriver.promise.ControlFlow</a></code><dd><p>The control flow to use, or
<code>null</code> to</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setEnableNativeEvents" class="function"><div><h3>setEnableNativeEvents(<wbr>enabled)<span class="codelink"><a href="source/builder.js.src.html#l264">code »</a></span></h3><p>Sets whether native events should be used.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>enabled<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd><p>Whether to enable native events.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setFirefoxOptions" class="function"><div><h3>setFirefoxOptions(<wbr>options)<span class="codelink"><a href="source/builder.js.src.html#l319">code »</a></span></h3><p>Sets Firefox specific <a href="module_selenium-webdriver_firefox_class_Options.html">options</a>
for drivers created by this builder. Any logging or proxy settings defined
on the given options will take precedence over those set through
<a href="module_selenium-webdriver_builder_class_Builder.html#setLoggingPrefs"><code>#setLoggingPrefs</code></a> and <a href="module_selenium-webdriver_builder_class_Builder.html#setProxy"><code>#setProxy</code></a>, respectively.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>options<code>firefox.Options</code><dd><p>The FirefoxDriver options to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setIeOptions" class="function"><div><h3>setIeOptions(<wbr>options)<span class="codelink"><a href="source/builder.js.src.html#l349">code »</a></span></h3><p>Sets Internet Explorer specific
<a href="module_selenium-webdriver_ie_class_Options.html">options</a> for drivers created by
this builder. Any proxy settings defined on the given options will take
precedence over those set through <a href="module_selenium-webdriver_builder_class_Builder.html#setProxy"><code>#setProxy</code></a>.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>options<code>ie.Options</code><dd><p>The IEDriver options to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setLoggingPrefs" class="function"><div><h3>setLoggingPrefs(<wbr>prefs)<span class="codelink"><a href="source/builder.js.src.html#l253">code »</a></span></h3><p>Sets the logging preferences for the created session. Preferences may be
changed by repeated calls, or by calling <a href="module_selenium-webdriver_builder_class_Builder.html#withCapabilities"><code>#withCapabilities</code></a>.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>prefs<code>(<a href="class_webdriver_logging_Preferences.html">webdriver.logging.Preferences</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>)</code><dd><p>The
desired logging preferences.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setOperaOptions" class="function"><div><h3>setOperaOptions(<wbr>options)<span class="codelink"><a href="source/builder.js.src.html#l334">code »</a></span></h3><p>Sets Opera specific <a href="module_selenium-webdriver_opera_class_Options.html">options</a> for
drivers created by this builder. Any logging or proxy settings defined on the
given options will take precedence over those set through
<a href="module_selenium-webdriver_builder_class_Builder.html#setLoggingPrefs"><code>#setLoggingPrefs</code></a> and <a href="module_selenium-webdriver_builder_class_Builder.html#setProxy"><code>#setProxy</code></a>, respectively.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>options<code>opera.Options</code><dd><p>The OperaDriver options to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setProxy" class="function"><div><h3>setProxy(<wbr>config)<span class="codelink"><a href="source/builder.js.src.html#l240">code »</a></span></h3><p>Sets the proxy configuration to use for WebDriver clients created by this
builder. Any calls to <a href="module_selenium-webdriver_builder_class_Builder.html#withCapabilities"><code>#withCapabilities</code></a> after this function will
overwrite these settings.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>config<code>{proxyType: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>}</code><dd><p>The configuration to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setSafariOptions" class="function"><div><h3>setSafariOptions(<wbr>options)<span class="codelink"><a href="source/builder.js.src.html#l364">code »</a></span></h3><p>Sets Safari specific <a href="module_selenium-webdriver_safari_class_Options.html">options</a>
for drivers created by this builder. Any logging settings defined on the
given options will take precedence over those set through
<a href="module_selenium-webdriver_builder_class_Builder.html#setLoggingPrefs"><code>#setLoggingPrefs</code></a>.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>options<code>safari.Options</code><dd><p>The Safari options to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="setScrollBehavior" class="function"><div><h3>setScrollBehavior(<wbr>behavior)<span class="codelink"><a href="source/builder.js.src.html#l276">code »</a></span></h3><p>Sets how elements should be scrolled into view for interaction.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>behavior<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The desired scroll behavior: either 0 to align with
the top of the viewport or 1 to align with the bottom.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="usingServer" class="function"><div><h3>usingServer(<wbr>url)<span class="codelink"><a href="source/builder.js.src.html#l147">code »</a></span></h3><p>Sets the URL of a remote WebDriver server to use. Once a remote URL has been
specified, the builder direct all new clients to that server. If this method
is never called, the Builder will attempt to create all clients locally.</p>
<p>As an alternative to this method, you may also set the <code>SELENIUM_REMOTE_URL</code>
environment variable.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>url<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The URL of a remote server to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="usingWebDriverProxy" class="function"><div><h3>usingWebDriverProxy(<wbr>proxy)<span class="codelink"><a href="source/builder.js.src.html#l170">code »</a></span></h3><p>Sets the URL of the proxy to use for the WebDriver's HTTP connections.
If this method is never called, the Builder will create a connection without
a proxy.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>proxy<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The URL of a proxy to use.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div><hr class="fn-sep"><div id="withCapabilities" class="function"><div><h3>withCapabilities(<wbr>capabilities)<span class="codelink"><a href="source/builder.js.src.html#l192">code »</a></span></h3><p>Sets the desired capabilities when requesting a new session. This will
overwrite any previously set capabilities.</p>
<div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>capabilities<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code><dd><p>The desired
capabilities for a new session.</p>
</dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="module_selenium-webdriver_builder_class_Builder.html">Builder</a></code><dd><p>A self reference.</p>
</dl></div></div></div></div></article><nav><h3><a href="index.html" tabindex="2">Overview</a></h3><div><input type="checkbox" id="nav-modules" checked/><label for="nav-modules"><h3><span class="selectable" tabindex="2">Modules</span></h3></label><div id="nav-modules-view"></div></div><div><input type="checkbox" id="nav-types" checked/><label for="nav-types"><h3><span class="selectable" tabindex="2">Types</span></h3></label><div id="nav-types-view"></div></div><h3><a href="Changes.html" tabindex="2">Changes</a></h3></nav></main><footer><div><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></div></footer><script src="types.js"></script><script src="dossier.js"></script>