You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
10 KiB
73 lines
10 KiB
<!DOCTYPE html><meta charset="UTF-8"><meta http-equiv="Content-Language" content="en" /><title>selenium-webdriver/testing</title><link href="dossier.css" rel="stylesheet" type="text/css"><div id="main-wrapper"><input type="checkbox" id="sidenav-toggle" /><main><header><h1>Module selenium-webdriver/testing</h1><a class="source" href="/usr/local/google/home/jleyba/dev/selenium/build/javascript/node/selenium-webdriver/docs/source/testing/index.js.src.html">code »</a></header><section><p>Provides wrappers around the following global functions from
|
|
<a href="http://visionmedia.github.io/mocha/">Mocha's BDD interface</a>:
|
|
<ul>
|
|
<li>after
|
|
<li>afterEach
|
|
<li>before
|
|
<li>beforeEach
|
|
<li>it
|
|
<li>it.only
|
|
<li>it.skip
|
|
<li>xit
|
|
</ul>
|
|
|
|
<p>The provided wrappers leverage the <code class="type"><a href="class_webdriver_promise_ControlFlow.html">webdriver.promise.ControlFlow</a></code>
|
|
to simplify writing asynchronous tests:
|
|
<pre><code>
|
|
var webdriver = require('selenium-webdriver'),
|
|
portprober = require('selenium-webdriver/net/portprober'),
|
|
remote = require('selenium-webdriver/remote'),
|
|
test = require('selenium-webdriver/testing');
|
|
|
|
test.describe('Google Search', function() {
|
|
var driver, server;
|
|
|
|
test.before(function() {
|
|
server = new remote.SeleniumServer(
|
|
'path/to/selenium-server-standalone.jar',
|
|
{port: portprober.findFreePort()});
|
|
server.start();
|
|
|
|
driver = new webdriver.Builder().
|
|
withCapabilities({'browserName': 'firefox'}).
|
|
usingServer(server.address()).
|
|
build();
|
|
});
|
|
|
|
test.after(function() {
|
|
driver.quit();
|
|
server.stop();
|
|
});
|
|
|
|
test.it('should append query to title', function() {
|
|
driver.get('http://www.google.com');
|
|
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
|
driver.findElement(webdriver.By.name('btnG')).click();
|
|
driver.wait(function() {
|
|
return driver.getTitle().then(function(title) {
|
|
return 'webdriver - Google Search' === title;
|
|
});
|
|
}, 1000, 'Waiting for title to update');
|
|
});
|
|
});
|
|
</code></pre>
|
|
|
|
<p>You may conditionally suppress a test function using the exported
|
|
"ignore" function. If the provided predicate returns true, the attached
|
|
test case will be skipped:
|
|
<pre><code>
|
|
test.ignore(maybe()).it('is flaky', function() {
|
|
if (Math.random() < 0.5) throw Error();
|
|
});
|
|
|
|
function maybe() { return Math.random() < 0.5; }
|
|
</code></pre></section><div id="visibility-controls"><b>Show:</b><label for="show-public"><span><input type="checkbox" id="show-public" checked/></span>Public</label><label for="show-protected"><span><input type="checkbox" id="show-protected"/></span>Protected</label><label for="show-private"><span><input type="checkbox" id="show-private"/></span>Private</label></div><section id="static-functions"><h2>Functions</h2><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l203">code »</a><span class="member"><a name="after">after</a> <span class="args">( fn )</span></span></div><p>Register a function to call after the current suite finishes.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>fn: <code class="type">function()</code><dd>.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l209">code »</a><span class="member"><a name="afterEach">afterEach</a> <span class="args">( fn )</span></span></div><p>Register a function to call after each test in a suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>fn: <code class="type">function()</code><dd>.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l215">code »</a><span class="member"><a name="before">before</a> <span class="args">( fn )</span></span></div><p>Register a function to call before the current suite starts.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>fn: <code class="type">function()</code><dd>.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l221">code »</a><span class="member"><a name="beforeEach">beforeEach</a> <span class="args">( fn )</span></span></div><p>Register a function to call before each test in a suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>fn: <code class="type">function()</code><dd>.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l188">code »</a><span class="member"><a name="describe">describe</a> <span class="args">( name, fn )</span></span></div><p>Registers a new test suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>name: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The suite name.<dt>fn: <code class="type">function()=</code><dd>The suite function, or <code >undefined</code> to define
|
|
a pending test suite.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l248">code »</a><span class="member"><a name="ignore">ignore</a> <span class="args">( predicateFn )</span> ⇒ <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div><p>Ignores the test chained to this function if the provided predicate returns
|
|
true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>predicateFn: <code class="type">function(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code><dd>A predicate to call to determine
|
|
if the test should be suppressed. This function MUST be synchronous.</dl><tr><th>Returns<tr><td><dl>An object with wrapped versions of <code class="type"><a class="unresolved-link">#it()</a></code> and
|
|
<code class="type"><a class="unresolved-link">#describe()</a></code> that ignore tests as indicated by the predicate.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l238">code »</a><span class="member"><a name="iit">iit</a> <span class="args">( name, fn )</span></span></div><p>An alias for <code class="type"><a class="unresolved-link">#it()</a></code> that flags the test as the only one that should
|
|
be run within the current suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>name: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The test name.<dt>fn: <code class="type">function()=</code><dd>The test function, or <code >undefined</code> to define
|
|
a pending test case.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l229">code »</a><span class="member"><a name="it">it</a> <span class="args">( name, fn )</span></span></div><p>Add a test to the current suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>name: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The test name.<dt>fn: <code class="type">function()=</code><dd>The test function, or <code >undefined</code> to define
|
|
a pending test case.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l196">code »</a><span class="member"><a name="xdescribe">xdescribe</a> <span class="args">( name, fn )</span></span></div><p>Defines a suppressed test suite.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>name: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The suite name.<dt>fn: <code class="type">function()=</code><dd>The suite function, or <code >undefined</code> to define
|
|
a pending test suite.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/testing/index.js.src.html#l246">code »</a><span class="member"><a name="xit">xit</a> <span class="args">( name, fn )</span></span></div><p>Adds a test to the current suite while suppressing it so it is not run.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>name: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The test name.<dt>fn: <code class="type">function()=</code><dd>The test function, or <code >undefined</code> to define
|
|
a pending test case.</dl></table></div></details></div></div></section></main><nav id="topnav"><div><div id="menubutton"><label for="sidenav-toggle">Menu</label></div><form id="searchbox"><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></nav><nav id="sidenav"><input type="checkbox" id="sidenav-types-ctrl" /><input type="checkbox" id="sidenav-files-ctrl" /><input type="checkbox" id="sidenav-modules-ctrl" /><a id="sidenav-overview"><div><h4>Overview</h4></div></a><div id="sidenav-types"><label for="sidenav-types-ctrl"><h4>Types</h4></label><i>No data</i></div><div id="sidenav-modules"><label for="sidenav-modules-ctrl"><h4>Modules</h4></label><i>No data</i></div><div id="sidenav-files"><label for="sidenav-files-ctrl"><h4>Files</h4></label><i>No data</i></div><a href="license.html"><div><h4>License</h4></div></a></nav><div id="push-footer"></div></div><footer><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></footer><script src="types.js"></script><script src="dossier.js"></script> |