UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

99 lines 17.8 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>Assertion</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>Namespace:</b> <a href="namespace_webdriver_testing.html">webdriver.testing</a></div><div class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l90">View Source</a></div><h1>class Assertion</h1><p>Utility for performing assertions against a given <code>value</code>. If the value is a <a href="class_webdriver_promise_Promise.html"><code>webdriver.promise.Promise</code></a>, this assertion will wait for it to resolve before applying any matchers.</p> <h3>new Assertion(<wbr>value)</h3><div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code>*</code><dd><p>The value to wrap and apply matchers to.</p> </dl></div></div><h2>Instance Methods</h2><div id="apply" class="function"><div><h3>apply(<wbr>matcher, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l149">code »</a></span></h3><p>Asserts that the given <code>matcher</code> accepts the value wrapped by this instance. If the wrapped value is a promise, this function will defer applying the assertion until the value has been resolved. Otherwise, it will be applied immediately.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>matcher<code>goog.labs.testing.Matcher</code><dd><p>The matcher to apply</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The deferred assertion result, or <code>null</code> if the assertion was immediately applied.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="closeTo" class="function"><div><h3>closeTo(<wbr>value, range, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l231">code »</a></span></h3><p>Asserts that the wrapped value is a number within a given distance of an expected value.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The expected value.</p> <dt>range<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The maximum amount the actual value is permitted to differ from the expected value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="contains" class="function"><div><h3>contains(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l294">code »</a></span></h3><p>Asserts that the wrapped value is a string or array-like structure containing the given value.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code>*</code><dd><p>The expected value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="endsWith" class="function"><div><h3>endsWith(<wbr>suffix, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l307">code »</a></span></h3><p>Asserts that the wrapped value is a string ending with the given suffix.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>suffix<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The expected suffix.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="equalTo" class="function"><div><h3>equalTo(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l348">code »</a></span></h3><p>Asserts that the value managed by this assertion is strictly equal to the given <code>value</code>.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code>*</code><dd><p>The expected value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="greaterThan" class="function"><div><h3>greaterThan(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l170">code »</a></span></h3><p>Asserts that the value managed by this assertion is a number strictly greater than <code>value</code>.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The minimum value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="greaterThanEqualTo" class="function"><div><h3>greaterThanEqualTo(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l185">code »</a></span></h3><p>Asserts that the value managed by this assertion is a number &gt;&#61; the given value.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The minimum value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="instanceOf" class="function"><div><h3>instanceOf(<wbr>ctor, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l245">code »</a></span></h3><p>Asserts that the wrapped value is an instance of the given class.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>ctor<code>Function</code><dd><p>The expected class constructor.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isFalse" class="function"><div><h3>isFalse()<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l366">code »</a></span></h3><p>Asserts that the value managed by this assertion is strictly false.</p> <div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isNull" class="function"><div><h3>isNull(<wbr>opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l257">code »</a></span></h3><p>Asserts that the wrapped value is null.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isNullOrUndefined" class="function"><div><h3>isNullOrUndefined(<wbr>opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l279">code »</a></span></h3><p>Asserts that the wrapped value is null or undefined.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isTrue" class="function"><div><h3>isTrue()<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l357">code »</a></span></h3><p>Asserts that the value managed by this assertion is strictly true.</p> <div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="isUndefined" class="function"><div><h3>isUndefined(<wbr>opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l268">code »</a></span></h3><p>Asserts that the wrapped value is undefined.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="lessThan" class="function"><div><h3>lessThan(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l200">code »</a></span></h3><p>Asserts that the value managed by this assertion is a number strictly less than the given value.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The maximum value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="lessThanEqualTo" class="function"><div><h3>lessThanEqualTo(<wbr>value, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l214">code »</a></span></h3><p>Asserts that the value managed by this assertion is a number &lt;&#61; the given value.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>value<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code><dd><p>The maximum value.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="matches" class="function"><div><h3>matches(<wbr>regex, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l335">code »</a></span></h3><p>Asserts that the wrapped value is a string that matches the given RegExp.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>regex<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp">RegExp</a></code><dd><p>The regex to test.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="startsWith" class="function"><div><h3>startsWith(<wbr>prefix, opt_message)<span class="codelink"><a href="source/lib/webdriver/testing/asserts.js.src.html#l321">code »</a></span></h3><p>Asserts that the wrapped value is a string starting with the given prefix.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>prefix<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd><p>The expected prefix.</p> <dt>opt_message<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd><p>A message to include if the matcher does not accept the value wrapped by this assertion.</p> </dl></div><div class="fn-details"><div><b>Returns</b></div><dl><dt><code><a href="class_webdriver_promise_Promise.html">webdriver.promise.Promise</a></code><dd><p>The assertion result.</p> </dl></div></div></div></div><h2>Instance Properties</h2><div id="is" class="property"><dl><dt><a href="source/lib/webdriver/testing/asserts.js.src.html#l101">is</a><code><a href="class_webdriver_testing_Assertion.html">webdriver.testing.Assertion</a></code><dd><p>A self reference provided for writing fluent assertions: webdriver.testing.assert(x).is.equalTo(y);</p> </dl></div><div id="not" class="property"><dl><dt><a href="source/lib/webdriver/testing/asserts.js.src.html#l108">not</a><code><a href="class_webdriver_testing_NegatedAssertion.html">webdriver.testing.NegatedAssertion</a></code><dd><p>Negates any matchers applied to this instance&#39;s value: webdriver.testing.assert(x).not.equalTo(y);</p> </dl></div><h2>Types</h2><dl><dt><a href="class_webdriver_testing_Assertion_DelegatingMatcher_.html">Assertion.DelegatingMatcher_</a><dd><p>Wraps an object literal implementing the Matcher interface.</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>