UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

70 lines (69 loc) 8.08 kB
<!DOCTYPE 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>webdriver.logging</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="codelink"><a href="source/lib/webdriver/logging.js.src.html#l67">View Source</a></div><h1>namespace webdriver.logging</h1><p>Defines WebDriver&#39;s logging system. The logging system is broken into major components: local and remote logging.</p> <p>The local logging API, which is anchored by the <a href="class_webdriver_logging_Logger.html"><code>Logger</code></a> class, is similar to Java&#39;s logging API. Loggers, retrieved by <a href="namespace_webdriver_logging.html#getLogger"><code>webdriver.logging.getLogger</code></a>, use hierarchical, dot-delimited namespaces (e.g. &#34;&#34; &gt; &#34;webdriver&#34; &gt; &#34;webdriver.logging&#34;). Recorded log messages are represented by the <a href="class_webdriver_logging_LogRecord.html"><code>LogRecord</code></a> class. You can capture log records by <a href="class_webdriver_logging_Logger.html#addHandler">attaching</a> a handler function to the desired logger. For convenience, you can quickly enable logging to the console by simply calling <a href="namespace_webdriver_logging.html#installConsoleHandler"><code>webdriver.logging.installConsoleHandler()</code></a>.</p> <p>The <a href="https://github.com/SeleniumHQ/selenium/wiki/Logging">remote logging API</a> allows you to retrieve logs from a remote WebDriver server. This API uses the <a href="class_webdriver_logging_Preferences.html"><code>Preferences</code></a> class to define desired log levels prior to create a WebDriver session:</p> <pre><code>var prefs &#61; new webdriver.logging.Preferences(); prefs.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.DEBUG); var caps &#61; webdriver.Capabilities.chrome(); caps.setLoggingPrefs(prefs); // ... </code></pre> <p>Remote log entries are represented by the <a href="class_webdriver_logging_Entry.html"><code>Entry</code></a> class and may be retrieved via <a href="class_webdriver_WebDriver_Logs.html"><code>webdriver.WebDriver.Logs</code></a>:</p> <pre><code>driver.manage().logs().get(webdriver.logging.Type.BROWSER) .then(function(entries) { entries.forEach(function(entry) { console.log(&#39;[%s] %s&#39;, entry.level.name, entry.message); }); }); </code></pre> <p><strong>NOTE:</strong> Only a few browsers support the remote logging API (notably Firefox and Chrome). Firefox supports basic logging functionality, while Chrome exposes robust <a href="https://sites.google.com/a/chromium.org/chromedriver/logging">performance logging</a> options. Remote logging is still considered a non-standard feature, and the APIs exposed by this module for it are non-frozen. Once logging is officially defined by the <a href="http://www.w3.org/TR/webdriver/">W3C WebDriver spec</a>, this module will be updated to use a consistent API for local and remote logging.</p> <h2>Functions</h2><div id="addConsoleHandler" class="function"><div><h3>addConsoleHandler(<wbr>opt_logger)<span class="codelink"><a href="source/lib/webdriver/logging.js.src.html#l149">code »</a></span></h3><p>Adds the console handler to the given logger. The console handler will log all messages using the JavaScript Console API.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_logger<code>?<a href="class_webdriver_logging_Logger.html">webdriver.logging.Logger</a>=</code><dd><p>The logger to add the handler to; defaults to the root logger.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getLevel" class="function"><div><h3>getLevel(<wbr>nameOrValue)<span class="codelink"><a href="source/lib/webdriver/logging.js.src.html#l199">code »</a></span></h3><p>Converts a level name or value to a <a href="class_webdriver_logging_Level.html"><code>webdriver.logging.Level</code></a> value. If the name/value is not recognized, <a href="class_webdriver_logging_Level.html#Level.ALL"><code>webdriver.logging.Level.ALL</code></a> will be returned.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>nameOrValue<code>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code><dd><p>The log level name, or value, to convert .</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_logging_Level.html">webdriver.logging.Level</a></code><dd><p>The converted level.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="getLogger" class="function"><div><h3>getLogger(<wbr>opt_name)<span class="codelink"><a href="source/lib/webdriver/logging.js.src.html#l107">code »</a></span></h3><p>Finds a named logger.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_name<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>The dot-delimited logger name, such as &#34;webdriver.logging.Logger&#34;. Defaults to the name of the root logger.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_logging_Logger.html">webdriver.logging.Logger</a></code><dd><p>The named logger.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="installConsoleHandler" class="function"><div><h3>installConsoleHandler()<span class="codelink"><a href="source/lib/webdriver/logging.js.src.html#l159">code »</a></span></h3><p>Installs the console log handler on the root logger.</p> </div></div><hr class="fn-sep"><div id="removeConsoleHandler" class="function"><div><h3>removeConsoleHandler(<wbr>opt_logger)<span class="codelink"><a href="source/lib/webdriver/logging.js.src.html#l171">code »</a></span></h3><p>Removes the console log handler from the given logger.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_logger<code>?<a href="class_webdriver_logging_Logger.html">webdriver.logging.Logger</a>=</code><dd><p>The logger to remove the handler from; defaults to the root logger.</p> </dl></div></div></div></div><h2>Types</h2><dl><dt><a href="class_webdriver_logging_Entry.html">Entry</a><dd><p>A single log entry recorded by a WebDriver component, such as a remote WebDriver server.</p> <dt><a href="class_webdriver_logging_Level.html">Level</a><dd><p>The Level class defines a set of standard logging levels that can be used to control logging output.</p> <dt><a href="class_webdriver_logging_LogRecord.html">LogRecord</a><dd><p>LogRecord objects are used to pass logging requests between the logging framework and individual log Handlers.</p> <dt><a href="class_webdriver_logging_Logger.html">Logger</a><dd><p>The Logger is an object used for logging debug messages.</p> <dt><a href="class_webdriver_logging_Preferences.html">Preferences</a><dd><p>Describes the log preferences for a WebDriver session.</p> <dt><a href="enum_webdriver_logging_Type.html">Type</a><dd><p>No description.</p> </dl></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>