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

mocha-node-webdriver

v0.0.1

Published

An example of configuring mocha to drive in-browser tests from node via webdriver.

Downloads

2

Readme

mocha-node-webdriver

An example of using mocha to write web app integration tests that run in node.js and execute through a browser using Selenium WebDriver.

This repository contains a minimal configuration for writing integration tests:

  • in JavaScript
  • that execute in node.js
  • written for the mocha test-runner
  • using selenium-webdriver to control a browser
  • that can access either remote or local servers
  • which start/stop the local server instance as needed

There is a trivial web "application" for use as a test target under the directory local_server. It has its own package.json file and has to be npm installed separately, but is otherwise boring.

To run the tests in this example, you'll need to have git, node, npm, and the Chrome browser installed already. If you don't, or the versions don't match this code's requirements, error messages will let you know. In addition, setup chromedriver for your system Once prerequisites in place, follow these steps particular to this example:

  1. go to somewhere you want to keep your local copy of this repository
  2. git clone https://github.com/gleneivey/mocha-node-webdriver.git
  3. cd mocha-node-webdriver
  4. npm install
  5. cd local_server
  6. npm install
  7. cd ..
  8. grunt

The Gruntfile in this example defines three tasks, including the default which is a union of the other two. grunt local launches a local web server, opens the Chrome browser, and then navigates the browser to the server (localhost:3000) to execute a handful of trivial tests. grunt remote launches Chrome and perform tests against two common public web services. Simply executing grunt runs both sets of tests. If you've been able to install and things are configured correctly, mocha should run and report "6 passing" tests.

Details of Note

  • The default grunt task which runs all the tests does not simply invoke the other two tasks. Instead, it has its own mochacli configuration that covers all the test files. Composing the other two tasks would run mocha twice, which would cause the test browser to be launched and closed twice.
  • There are several things that would be configureable in a real system (the local server port, test file paths, etc.) that have been hard-coded for simplicity/clarity.
  • Integration tests are slow. The file test/mocha.opts is used to increase mocha's default test timeout from 2 seconds to 30 seconds. Hopefully this is high enough to accommodate any system you're trying to run these tests on, but if you get timeout failures, try increasing the value here.
  • The file test/for_all_tests.js contains code that puts the driver variable into the global name space, as well as mocha before() and after() calls that initialize and close the browser and WebDriver sessions. This file must be included in the file list given to mocha, and cannot be named by the --require option or required from within the test files.
  • The remote tests don't perform a search on www.google.com like many other Selenuim WebDriver examples do. It turns out that it's actually difficult for Chrome to navigate off a Google results page with a simple driver.get(). When putting this example together, the results page was constantly "navigating" itself (to check to see if it could sing in to Google+, etc.), and the Selenium-requested navigation worked less than 10% of the time.