NOTE: This module is not quite ready! Only a few commands work, and it's hard-wired to use Phantomjs. More to follow though.
;var webdriver =By = webdriverByuntil = webdriveruntil;var driver =;;
There are four improvements that we'd like to make:
() => driver.getTitle());
catch()in Mocha by returning a promise;
untilwithout having to repeat the declarations at the top of every test file.
The first three points should all be possible, but since the promises that WebDriver returns are not 'compatible' with those used in other libraries -- such as Mocha and Chai as Promised -- they all fail.
For example, to use WebDriver commands like
getTitle() we are obliged to nest them in a simple function:
However, what we should be able to do is simply pass a reference to the WebDriver function, like this:
Although WebDriver claims to return promises for commands the type of promises being used are not compatible with other libraries -- like Mocha -- and what should be a chain of promises turns out not to be (i.e., the promises are not being 'followed'). To get this to work we have to wrap calls to WebDriver functions with a more 'standard' promise:
To make this wrapping easier, the
webdriver-mocha module wraps all of the WebDriver commands with 'proper' promises and therefore allows the more direct syntax.
Note that doing this wrapping makes it possible to use Chai as Promised, which won't work with the promises that
WebDriver is using. It also means that we can take advantage of a key benefit of Mocha which is that if a test returns a promise then Mocha will handle rejected promises. This means we can dispense with calling
done() to terminate the test, and avoid the need to provide the
Rather than having to declare the imports and variables for WebDriver at the top of each test file we'd like to incude them as globals to Mocha. This module also facilitates that, making
Note that since this module takes responsibility for creating
driver it also takes responsibility for calling
driver.quit() when all tests are complete.
The example we began with can now be expressed like this:
let chai = ;chai;chai;;;
Note the addition of Chai as Promised, the removal of
driver.quit(), and -- thanks to the
return statement at the start of the test -- the omission of the two
webdriver-mocha module has given us:
untilin exactly the same way as many snippets of code to be found on the web, making it easy to include them, and;
Be sure to add
until as globals in your linting tool. For example, for ESLint we have:
See the two
.eslintrc files in this project for an example.