What sorts of assertions can we make?
All assertions start with a Sizzle-compatible css selector, for example:
Then we add the dom flag, like so:
Finally, we can add our assertion to the chain:
Test the text value of the dom against supplied string. Exact matches only.
Test the text value of the dom against supplied string. Partial matches allowed.
Test the text value of the dom against the regular expression.
Test the text value of the dom against the regular expression. (Same as
Check whether or not the element is displayed (can be scrolled off-screen)
Check whether or not the element is visible on-screen
Check whether or not the form element is disabled
Test how many elements exist in the dom with the supplied selector
Test the CSS style of the element (exact string match).
Test the value of a form field against supplied string.
Tests that the element has
warning as one of its class attributes.
Test an element's attribute value. Exact matches only. By omitting
value test simply checks for existance of attribute.
You can also always add a
not in there to negate the assertion:
Larger and smaller
Several of the assertion methods support the
smaller properties, which allow numeric comparisons. e.g. for
Test for a numeric value larger (>=) than 0.
Test for a numeric value smaller (<=) than 0.
Test for a numeric value not larger (<) than 0.
Test for a numeric value not smaller (>) than 0.
Other methods which support
Test for text with length larger (>=) than 0.
Test for number of elements matching
selector larger (>=) than 0.
Test for css attribute value larger (>=) than 0 (ignores units).
Test for attribute value larger (>=) than 0.
You can also add an
eventually to tell
chai-webdriver-promised to poll for the desired state up to the configured timeout (see Setup below):
Everything returns a promise
All of these assertions return a
Q promise, so you can just return the promise if you're using mocha.
Setup is pretty easy. Just:
// Start with a webdriver instance:var sw = ;var driver =//optional timeout in ms to use with eventually (defaults to 1000)var timeout = 15000;//optional interval in ms to use when polling (defaults to 200)var interval = 100;// And then...var chai = ;var chaiWebdriver = ;chai;// And you're good to go!chai;
$EDITOR index.js # edit index.jsnpm test # run the specs