UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

74 lines (69 loc) 8.54 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>selenium-webdriver/testing</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/testing/index.js.src.html#l69">View Source</a></div><h1>module selenium-webdriver/testing</h1><p>Provides wrappers around the following global functions from <a href="https://github.com/mochajs/mocha">Mocha&#39;s BDD interface</a>:</p> <ul><li>after</li><li>afterEach</li><li>before</li><li>beforeEach</li><li>it</li><li>it.only</li><li>it.skip</li><li>xit</li></ul> <p>The provided wrappers leverage the <a href="class_webdriver_promise_ControlFlow.html"><code>webdriver.promise.ControlFlow</code></a> to simplify writing asynchronous tests:</p> <pre><code>var By &#61; require(&#39;selenium-webdriver&#39;).By, until &#61; require(&#39;selenium-webdriver&#39;).until, firefox &#61; require(&#39;selenium-webdriver/firefox&#39;), test &#61; require(&#39;selenium-webdriver/testing&#39;); test.describe(&#39;Google Search&#39;, function() { var driver; test.before(function() { driver &#61; new firefox.Driver(); }); test.after(function() { driver.quit(); }); test.it(&#39;should append query to title&#39;, function() { driver.get(&#39;http://www.google.com/ncr&#39;); driver.findElement(By.name(&#39;q&#39;)).sendKeys(&#39;webdriver&#39;); driver.findElement(By.name(&#39;btnG&#39;)).click(); driver.wait(until.titleIs(&#39;webdriver - Google Search&#39;), 1000); }); }); </code></pre> <p>You may conditionally suppress a test function using the exported &#34;ignore&#34; function. If the provided predicate returns true, the attached test case will be skipped:</p> <pre><code>test.ignore(maybe()).it(&#39;is flaky&#39;, function() { if (Math.random() &lt; 0.5) throw Error(); }); function maybe() { return Math.random() &lt; 0.5; } </code></pre> <h2>Functions</h2><div id="after" class="function"><div><h3>after(<wbr>fn)<span class="codelink"><a href="source/testing/index.js.src.html#l213">code »</a></span></h3><p>Register a function to call after the current suite finishes.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>fn<code>function(): ?</code><dd><p>.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="afterEach" class="function"><div><h3>afterEach(<wbr>fn)<span class="codelink"><a href="source/testing/index.js.src.html#l219">code »</a></span></h3><p>Register a function to call after each test in a suite.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>fn<code>function(): ?</code><dd><p>.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="before" class="function"><div><h3>before(<wbr>fn)<span class="codelink"><a href="source/testing/index.js.src.html#l225">code »</a></span></h3><p>Register a function to call before the current suite starts.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>fn<code>function(): ?</code><dd><p>.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="beforeEach" class="function"><div><h3>beforeEach(<wbr>fn)<span class="codelink"><a href="source/testing/index.js.src.html#l231">code »</a></span></h3><p>Register a function to call before each test in a suite.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>fn<code>function(): ?</code><dd><p>.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="describe" class="function"><div><h3>describe(<wbr>name, fn)<span class="codelink"><a href="source/testing/index.js.src.html#l198">code »</a></span></h3><p>Registers a new test suite.</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 suite name.</p> <dt>fn<code>function(): ?=</code><dd><p>The suite function, or <code>undefined</code> to define a pending test suite.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="ignore" class="function"><div><h3>ignore(<wbr>predicateFn)<span class="codelink"><a href="source/testing/index.js.src.html#l258">code »</a></span></h3><p>Ignores the test chained to this function if the provided predicate returns true.</p> <div><div class="fn-details"><div><b>Parameters</b></div><dl><dt>predicateFn<code>function(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd><p>A predicate to call to determine if the test should be suppressed. This function MUST be synchronous.</p> </dl></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/Object">Object</a></code><dd><p>An object with wrapped versions of <a href="module_selenium-webdriver_testing.html#it"><code>#it()</code></a> and <a href="module_selenium-webdriver_testing.html#describe"><code>#describe()</code></a> that ignore tests as indicated by the predicate.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="iit" class="function"><div><h3>iit(<wbr>name, fn)<span class="codelink"><a href="source/testing/index.js.src.html#l248">code »</a></span></h3><p>An alias for <a href="module_selenium-webdriver_testing.html#it"><code>#it()</code></a> that flags the test as the only one that should be run within the current suite.</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 test name.</p> <dt>fn<code>function(): ?=</code><dd><p>The test function, or <code>undefined</code> to define a pending test case.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="it" class="function"><div><h3>it(<wbr>name, fn)<span class="codelink"><a href="source/testing/index.js.src.html#l239">code »</a></span></h3><p>Add a test to the current suite.</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 test name.</p> <dt>fn<code>function(): ?=</code><dd><p>The test function, or <code>undefined</code> to define a pending test case.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="xdescribe" class="function"><div><h3>xdescribe(<wbr>name, fn)<span class="codelink"><a href="source/testing/index.js.src.html#l206">code »</a></span></h3><p>Defines a suppressed test suite.</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 suite name.</p> <dt>fn<code>function(): ?=</code><dd><p>The suite function, or <code>undefined</code> to define a pending test suite.</p> </dl></div></div></div></div><hr class="fn-sep"><div id="xit" class="function"><div><h3>xit(<wbr>name, fn)<span class="codelink"><a href="source/testing/index.js.src.html#l256">code »</a></span></h3><p>Adds a test to the current suite while suppressing it so it is not run.</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 test name.</p> <dt>fn<code>function(): ?=</code><dd><p>The test function, or <code>undefined</code> to define a pending test case.</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>