npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chai-webdriver

v1.2.3

Published

Build more expressive integration tests with some webdriver sugar for chai.js

Downloads

1,746

Readme

chai-webdriver Build Status Dependency Status NPM version

Provides selenium-webdriver sugar for the Chai assertion library. Allows you to create expressive integration tests:

expect('.frequency-field').dom.to.contain.text('One time')
expect('.toggle-pane').dom.to.not.be.visible()

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 as match above).
  • expect(selector).dom.to.be.visible() - Check whether or not the element is being rendered
  • expect(selector).dom.to.be.disabled() - Check whether or not the form element is disabled
  • expect(selector).dom.to.have.count(number) - Test how many elements exist in the dom with the supplied selector
  • expect(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 has warning as one of its class attributes.
  • expect(selector).dom.to.have.attribute('attribute', 'value') - Test an element's attribute against value as an exact match. By omitting value test simply checks for existance of attribute.
  • expect(selector).dom.to.have.attribute('attribute', /regex/) - Test an element's attribute 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 = require('selenium-webdriver');
var driver = new sw.Builder()
  .withCapabilities(sw.Capabilities.chrome())
  .build()

// And then...
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
chai.use(chaiWebdriver(driver));

// And you're good to go!
driver.get('http://github.com');
chai.expect('#site-container h1.heading').dom.to.not.contain.text("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.