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-promised

v4.0.3

Published

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

Downloads

107

Readme

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.eventually.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:

Text

Test the text value of the dom against supplied string. Exact matches only.

expect(selector).dom.to.have.text('string')

Text (contain)

Test the text value of the dom against supplied string. Partial matches allowed.

expect(selector).dom.to.contain.text('string')

Match

Test the text value of the dom against the regular expression.

expect(selector).dom.to.match(/regex/)

Text (regex)

Test the text value of the dom against the regular expression. (Same as match above).

expect(selector).dom.to.have.text(/regex/)

Displayed

Check whether or not the element is displayed (can be scrolled off-screen)

expect(selector).dom.to.be.displayed()

Visible

Check whether or not the element is visible on-screen

expect(selector).dom.to.be.visible()

Disabled

Check whether or not the form element is disabled

expect(selector).dom.to.be.disabled()

Count

Test how many elements exist in the dom with the supplied selector

expect(selector).dom.to.have.count(number)

Style

Test the CSS style of the element (exact string match).

expect(selector).dom.to.have.style('property', 'value')

Value

Test the value of a form field against supplied string.

expect(selector).dom.to.have.value('string')

HTML Class

Tests that the element has warning as one of its class attributes.

expect(selector).dom.to.have.htmlClass('warning')

Attribute

Test an element's attribute value. Exact matches only. By omitting value test simply checks for existance of attribute.

expect(selector).dom.to.have.attribute('attribute', 'value')

Not

You can also always add a not in there to negate the assertion:

expect(selector).dom.not.to.have.style('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.

expect('input[type=number]').dom.to.have.larger.value(0)

Test for a numeric value smaller (<=) than 0.

expect('input[type=number]').dom.to.have.smaller.value(0)

Test for a numeric value not larger (<) than 0.

expect('input[type=number]').dom.not.to.have.larger.value(0)

Test for a numeric value not smaller (>) than 0.

expect('input[type=number]').dom.not.to.have.smaller.value(0)

Other methods which support larger and smaller:

Test for text with length larger (>=) than 0.

expect(selector).dom.to.have.larger.text(0)

Test for number of elements matching selector larger (>=) than 0.

expect(selector).dom.to.have.larger.count(0)

Test for css attribute value larger (>=) than 0 (ignores units).

expect(selector).dom.to.have.larger.style('width', 0)

Test for attribute value larger (>=) than 0.

expect(selector).dom.to.have.larger.attribute('offsetWidth', 0)

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):

expect(selector).dom.to.eventually.have.htmlClass('warning')

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 = require('selenium-webdriver');
var driver = new sw.Builder()
  .withCapabilities(sw.Capabilities.chrome())
  .build()

//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 = require('chai');
var chaiWebdriver = require('chai-webdriver-promised');
chai.use(chaiWebdriver(driver, timeout, interval));

// And you're good to go!
chai.describe('kitty test', function() {
  chai.before(function(done) {
    driver.get('http://github.com').then(done);
  });
  it('should not find a kitty', function() {
    return chai.expect('#site-container h1.heading').dom.to.not.contain.text("I'm a kitty!");
  });
});

Contributing

so easy.

$EDITOR index.js      # edit index.js
npm test              # run the specs

License

MIT.