module selenium-webdriver/testing

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

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

var By = require('selenium-webdriver').By,
    until = require('selenium-webdriver').until,
    firefox = require('selenium-webdriver/firefox'),
    test = require('selenium-webdriver/testing');

test.describe('Google Search', function() {
  var driver;

  test.before(function() {
    driver = new firefox.Driver();
  });

  test.after(function() {
    driver.quit();
  });

  test.it('should append query to title', function() {
    driver.get('http://www.google.com/ncr');
    driver.findElement(By.name('q')).sendKeys('webdriver');
    driver.findElement(By.name('btnG')).click();
    driver.wait(until.titleIs('webdriver - Google Search'), 1000);
  });
});

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; }

Functions

after(fn)code »

Register a function to call after the current suite finishes.

Parameters
fnfunction(): ?

.


afterEach(fn)code »

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

Parameters
fnfunction(): ?

.


before(fn)code »

Register a function to call before the current suite starts.

Parameters
fnfunction(): ?

.


beforeEach(fn)code »

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

Parameters
fnfunction(): ?

.


describe(name, fn)code »

Registers a new test suite.

Parameters
namestring

The suite name.

fnfunction(): ?=

The suite function, or undefined to define a pending test suite.


ignore(predicateFn)code »

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

Parameters
predicateFnfunction(): boolean

A predicate to call to determine if the test should be suppressed. This function MUST be synchronous.

Returns
Object

An object with wrapped versions of #it() and #describe() that ignore tests as indicated by the predicate.


iit(name, fn)code »

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

Parameters
namestring

The test name.

fnfunction(): ?=

The test function, or undefined to define a pending test case.


it(name, fn)code »

Add a test to the current suite.

Parameters
namestring

The test name.

fnfunction(): ?=

The test function, or undefined to define a pending test case.


xdescribe(name, fn)code »

Defines a suppressed test suite.

Parameters
namestring

The suite name.

fnfunction(): ?=

The suite function, or undefined to define a pending test suite.


xit(name, fn)code »

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

Parameters
namestring

The test name.

fnfunction(): ?=

The test function, or undefined to define a pending test case.