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 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; }
Show:
Functions
code »beforeEach ( fn )Register a function to call before each test in a suite.
Parameters |
---|
|
Ignores the test chained to this function if the provided predicate returns
true.
Parameters |
---|
|
Returns |
#it() and
#describe() that ignore tests as indicated by the predicate. |