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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mocha-selenium

v0.1.1

Published

Run mocha selenium acceptance tests in different browsers, in serial or parallel

Downloads

25

Readme

Mocha Selenium

Everything you need for selenium testing in node.js.

The Library

Setup and teardown with mocha's before and after.

  • gives you wd.driver Webdriver Client
  • start fresh instance of your app (if needed)
  • start webdriver server (if needed)
  • take screenshots after failed tests

Read the docs for more information on the options.

var expect = require('expect.js')
  , b = require('mocha-selenium').setup("Login Page", {
      appDir: path.dirname(__dirname),
      lastShot: "failed"
    });

describe('The login page', function () {
  this.timeout(20 * 1000)
  before(function (done) {
    b.get(b.baseUrl + '/login', done)
  })
  it('should work', function (done) {
    function fail(err) {
      b.haltChain()
      done(err)
    }
    b.chain({onError: fail})
     .fillInForm('.loginForm', {
       username: 'jsmith',
       password: '1830'
     })
     .clickByCss('.loginForm button.submit')
     // make sure we were redirected to the account page
     .url(function (err, url) {
       if (err) return fail(err)
       expect(url).to.match(/\/account$/)
       done()
     })
  })
})

Convenience functions added to the driver

In addition to the normal wd methods, there are the following:

General Methods

ensureCookie(name, value, done(err))

On the current page, if the cookie by the name of name with value value does not exist, set the cookie and refresh the page.

If value is a function, it is called with the current value of the cookie. If it returns a value other than the current cookie value, the cookie is set to that value.

fillInForm(data, [formSelector,] done(err))

Data is a map of "input name": "value to type". If formSelector is given, only inputs that are children of the given selector will be filled in. Otherwise, the first input in the document with the given name will be populated.

rel(url, done(err))

Gets b.baseUrl + url.

Element-specific methods

The following suffixes are available for these methods, mirroring the wd library:

ByClassName, ByCssSelector, ById, ByName, ByLinkText, ByPartialLinkText, ByTagName, ByXPath, ByCss.

I will use the ByCss suffix for demonstration.

  • textByCss(selector, done(err, value, element)
  • visibleByCss(selector, done(err, value, element)
  • valueByCss(selector, done(err, value, element)
  • clickByCss(selector, done(err, element)
  • waitAndGet(selector, timeout, done(err, element)
  • waitAndClickByCss(selector, timeout, done(err, element)

The Runner

Run your mocha selenium tests in parallel in mutliple browsers.

Usage

  Usage: mocha-selenium [options]

  Options:

    -h, --help               output usage information
    -V, --version            output the version number
    -e, --environment [env]  Pick the environment to run (host + browsers). Default: local
    -p, --parallel           Run the tests in parallel. Default: false
    -c, --config [file]      Specify the config file. Default: ./selenium.json
Config
{
  files: // filename or glob, or list of filenames or globs
  envs: { // a map of [envname] to an environment definition.
    local: [browserdef, ...] || {
      browsers: [browserdef, ...],
      inherits: // name or list of names of other environemnts. Their
                // browserdefs will be appended to the current env.
      // if no hostname is given, mocha-selenium will start its own
      // selenium drivers. Currently phantomjs and chrome are supported
      hostname: "ondemand.saucelabs.com",
      port: 80,
      auth: {
        type: 'plain',
        username: 'MyName',
        password: 'secret'
      } || {
        type: 'env', // the username and password are environmental variables
        username: 'SAUCE_USERNAME',
        password: 'SAUCE_ACCESS_KEY'
      }
    },
    otherenv: ...,
    ...
  }
}

Browserdef:

["browsername", "version", "platform"]

ex:
["internet explorer", "8", "Windows XP"]