Socket
Socket
Sign inDemoInstall

mocha-webdriver-runner

Package Overview
Dependencies
45
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mocha-webdriver-runner

Run Mocha tests using Selenium WebDriver


Version published
Weekly downloads
387
increased by117.42%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

mocha-webdriver-runner

npm Build status

Run Mocha tests in browsers using Selenium WebDriver.

Inspired by mocha-chrome, but with following features implemented from start:

  • drives browser using Selenium WebDriver, so you can run tests on everything that selenium WebDriver supports. Hint: it supports everything (tm).
  • runs reporters locally, in node environment so most of reporters (which are designed to work in node environment) should work out-of-box:
    • tested mocha builtins: spec, xunit, tap, etc ...
    • support for mochawesome (including usage of addContext)

That's it, have fun.

Install

$ npm install mocha-webdriver-runner

Usage

Prepare your tests to run in browser as described on Mocha website.

Add mocha-webdriver-runner browser side client:

 <script src="../node_modules/mocha-webdriver-runner/dist/mocha-webdriver-client.js"></script>

and install MochaWebdriverClient in global mocha instance:

  mocha.setup({ui: "bdd"});
+ MochaWebdriverClient.install(mocha);

Run the test suite:

SELENIUM_BROWSER=chrome npx mocha-webdriver-runner test/index.html

SELENIUM_BROWSER=firefox npx mocha-webdriver-runner test/index.html --reporter=tap

(assuming your tests are in test/index.html).

See package.json scripts and test/sample-suite/index-headless.html for reference.

Browser capabilities

Use -C key[=value] (or --capability) options to set requested browser capabilities. Value may be plain string, or JSON value, examples:

-C browserName=firefox
-C moz:firefoxOptions.args='["-headless"]'
-C browserName=chrome
-C chromeOptions.args='["--headless", "--window-size=300,300"]'

Useful links:

Selenium WebDriverJS accepts capabilities passed by environment variables as below:

SELENIUM_BROWSER=chrome
SELENIUM_BROWSER=firefox:52
SELENIUM_REMOTE_URL=http://my-selenium-grid:4444/wd/hub

See WebDriverJS Builder

API

Node.Js

From Node.js you can start tests using runMochaWebDriverTest.

// in node.js context
import { runMochaWebDriverTest } from "mocha-webdriver-runner";

const webDriverCapabilities = {
    browserName: "firefox"
};

runMochaWebDriverTest(webDriverCapabilities, "https://localhost:8080/test/index.html")
    .then(result => {
        // result is boolean i.e ok or not ok
        console.log("test result", result ? ":)" : ":(");
    })
    .catch(error => {
        // something bad happened with runner itself i.e webdriver error or something
    });

Browser general API

Browser module export global object MochaWebdriverClient.

Import examples:

<!-- from CDN -->
<script src="https://unpkg.com/mocha-webdriver-runner/dist/mocha-webdriver-client.js"></script>
<!-- from local node_modules -->
<script src="../node_modules/mocha-webdriver-runner/dist/mocha-webdriver-client.js"></script>

MochaWebdriverClient API

  • addMochaSource(mocha) - instruments mocha instance to send runner events back to mocha-selenium-runner process.

    Example:

    mocha.setup({ ui: "bdd" });
    MochaWebdriverClient.install(mocha);
    // load sources
    mocha.run();
    
  • addWorkerSource(worker: Worker) - forwards all mocha-selenium-runner related events from worker back to mocha-selenium-runner process (requires properly initialized mocha in worker context

    Example:

    const worker = new Worker("some-test-worker.js");
    MochaWebdriverClient.addWorkerSource(worker);
    

Examples:

Contribute

PRs accepted.

License

MIT © Zbigniew Zagórski

Keywords

FAQs

Last updated on 16 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc