Provides selenium-webdriver sugar for the Chai assertion library. Allows you to create expressive integration tests:
domtocontaintext'One time'domtoeventuallynotbe
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:
dom
Finally, we can add our assertion to the chain:
Text
Test the text value of the dom against supplied string. Exact matches only.
domtohavetext'string'
Text (contain)
Test the text value of the dom against supplied string. Partial matches allowed.
domtocontaintext'string'
Match
Test the text value of the dom against the regular expression.
domto
Text (regex)
Test the text value of the dom against the regular expression. (Same as match
above).
domtohavetext/regex/
Displayed
Check whether or not the element is displayed (can be scrolled off-screen)
domtobe
Visible
Check whether or not the element is visible on-screen
domtobe
Disabled
Check whether or not the form element is disabled
domtobedisabled
Count
Test how many elements exist in the dom with the supplied selector
domtohave
Style
Test the CSS style of the element (exact string match).
domtohavestyle'property' 'value'
Value
Test the value of a form field against supplied string.
domtohavevalue'string'
HTML Class
Tests that the element has warning
as one of its class attributes.
domtohave
Attribute
Test an element's attribute value. Exact matches only. By omitting value
test simply checks for existance of attribute.
domtohave
Not
You can also always add a not
in there to negate the assertion:
domnottohavestyle'property' 'value'
Larger and smaller
Several of the assertion methods support the larger
and smaller
properties, which allow numeric comparisons. e.g. for value()
:
Test for a numeric value larger (>=) than 0.
domtohavelargervalue0
Test for a numeric value smaller (<=) than 0.
domtohavesmallervalue0
Test for a numeric value not larger (<) than 0.
domnottohavelargervalue0
Test for a numeric value not smaller (>) than 0.
domnottohavesmallervalue0
Other methods which support larger
and smaller
:
Test for text with length larger (>=) than 0.
domtohavelargertext0
Test for number of elements matching selector
larger (>=) than 0.
domtohavelarger
Test for css attribute value larger (>=) than 0 (ignores units).
domtohavelargerstyle'width' 0
Test for attribute value larger (>=) than 0.
domtohavelarger
Eventually
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):
domtoeventuallyhave
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
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;
Contributing
so easy.
$EDITOR index.js # edit index.js npm test # run the specs
License
MIT.