# Module selenium-webdriver/testing

code »

Provides wrappers around the following global functions from Mocha's BDD interface:

- after
- afterEach
- before
- beforeEach
- it
- it.only
- it.skip
- xit

The provided wrappers leverage the webdriver.promise.ControlFlow to simplify writing asynchronous tests:

     var webdriver = require('selenium-webdriver'),
         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({
           jar: 'path/to/selenium-server-standalone.jar'
         });
         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');
       });
     });

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:

       test.ignore(maybe()).it('is flaky', function() {
         if (Math.random() < 0.5) throw Error();
       });

       function maybe() { return Math.random() < 0.5; }

Show:Public Protected Private

## Functions

code »after ( fn )

Register a function to call after the current suite finishes.

Parameters
fn: `function()` .

code »afterEach ( fn )

Register a function to call after each test in a suite.

Parameters
fn: `function()` .

code »before ( fn )

Register a function to call before the current suite starts.

Parameters
fn: `function()` .

code »beforeEach ( fn )

Register a function to call before each test in a suite.

Parameters
fn: `function()` .

code »describe ( name, fn )

Registers a new test suite.

Parameters
name: `string` The suite name. fn: `function()=` The suite function, or `undefined` to define a pending test suite.

code »ignore ( predicateFn ) ⇒ `!Object`

Ignores the test chained to this function if the provided predicate returns true.

Parameters
predicateFn: `function(): boolean` A predicate to call to determine if the test should be suppressed. This function MUST be synchronous.
Returns
An object with wrapped versions of `#it()` and `#describe()` that ignore tests as indicated by the predicate.

code »iit ( name, fn )

An alias for `#it()` that flags the test as the only one that should be run within the current suite.

Parameters
name: `string` The test name. fn: `function()=` The test function, or `undefined` to define a pending test case.

code »it ( name, fn )

Add a test to the current suite.

Parameters
name: `string` The test name. fn: `function()=` The test function, or `undefined` to define a pending test case.

code »xdescribe ( name, fn )

Defines a suppressed test suite.

Parameters
name: `string` The suite name. fn: `function()=` The suite function, or `undefined` to define a pending test suite.

code »xit ( name, fn )

Adds a test to the current suite while suppressing it so it is not run.

Parameters
name: `string` The test name. fn: `function()=` The test function, or `undefined` to define a pending test case.