Provides selenium-webdriver sugar for the Chai assertion library. Allows you to create expressive integration tests:
domtocontaintext'One time'domtonotbe
What sorts of assertions can we make?
All assertions start with a Sizzle-compatible css selector, for example:
expect('.list')
expect('div > h1')
expect('a[href=http://google.com]')
Then we add the dom flag, like so:
expect(selector).dom
Finally, we can add our assertion to the chain.
expect(selector).dom.to.have.text('string')
- Test the text value of the dom against supplied string. Exact matches only.expect(selector).dom.to.contain.text('string')
- Test the text value of the dom against supplied string. Partial matches allowed.expect(selector).dom.to.match(/regex/)
- Test the text value of the dom against the regular expression.expect(selector).dom.to.have.text(/regex/)
- Test the text value of the dom against the regular expression. (Same asmatch
above).expect(selector).dom.to.be.visible()
- Check whether or not the element is being renderedexpect(selector).dom.to.be.disabled()
- Check whether or not the form element is disabledexpect(selector).dom.to.have.count(number)
- Test how many elements exist in the dom with the supplied selectorexpect(selector).dom.to.have.style('property', 'value')
- Test the CSS style of the element. Exact matches only, unfortunately, for now.expect(selector).dom.to.have.value('string')
- Test the value of a form field against supplied string.expect(selector).dom.to.have.htmlClass('warning')
- Tests that the element haswarning
as one of its class attributes.expect(selector).dom.to.have.attribute('attribute', 'value')
- Test an element'sattribute
againstvalue
as an exact match. By omittingvalue
test simply checks for existance of attribute.expect(selector).dom.to.have.attribute('attribute', /regex/)
- Test an element'sattribute
against a regular expresssion.
You can also always add a not
in there to negate the assertion:
expect(selector).dom.not.to.have.style('property', 'value')
Asynchronous flow
Note that all these assertions are presumed to be asynchronous (using selenium-webdriver's promise chain). They can all take callbacks, or be chained with promises. For example:
expect(selector).dom.to.have.text('string', function(){...})
expect(selector).dom.to.have.text('string').then(function(){...})
Setup
Setup is pretty easy. Just:
// Start with a webdriver instance:var sw = ;var driver = // And then...var chai = ;var chaiWebdriver = ;chai; // And you're good to go!driver;chaidomtonotcontaintext"I'm a kitty!";
Contributing
so easy.
npm install # download the necessary development dependencies npm run-script build # compile coffee-script into javascript npm test # build and run the specs
License
MIT.