Code Monkey home page Code Monkey logo

webextensions-geckodriver's Introduction

WebExtensions GeckoDriver

When testing WebExtensions you might want to automatically load them into Firefox and do functional testing with geckodriver.

Installation

npm install --save-dev webextensions-geckodriver

Usage

const webExtensionsGeckoDriver = require('webextensions-geckodriver');
const webExtension = await webExtensionsGeckoDriver('/absolute/path/to/manifest.json');

Loads the WebExtension as Temporary Add-on into a new Firefox instance. See API docs for more details.

Example

manifest.json includes

  "browser_action": {
    "default_title": "Visit Example.com"
  },
  "applications": {
    "gecko": {
      "id": "@examplewebextension",
      "strict_min_version": "57.0"
    }
  }

Test could look like this (using mocha):

const path = require('path');
const assert = require('assert');

const webExtensionsGeckoDriver = require('webextensions-geckodriver');
const {webdriver} = webExtensionsGeckoDriver;

const manifestPath = path.resolve(path.join(__dirname, './path/to/manifest.json'));

describe('Example', () => {
  let geckodriver;

  before(async () => {
    const webExtension = await webExtensionsGeckoDriver(manifestPath);
    geckodriver = webExtension.geckodriver;
  });

  it('should have a Toolbar Button', async () => {
    const button = await geckodriver.wait(webdriver.until.elementLocated(
      // browser_actions automatically have applications.gecko.id as prefix
      // special chars in the id are replaced with _
      webdriver.By.id('_examplewebextension-browser-action')
    ), 1000);
    assert.equal(await button.getAttribute('tooltiptext'), 'Visit Example.com');
  });

  after(() => {
    geckodriver.quit();
  });
});

Full executable example is in the example directory.

API

Exported default function(path[, options])

  • path <string>, required, absolute path to the manifest.json file
  • options <object>, optional
    • binary <string>, optional, lets you set the binary that is passed to fx-runner. Possible values: firefox, beta, aurora, nightly, firefoxdeveloperedition. Defaults to: firefox.
    • autoInstall, <boolean>, optional, if set to false the extension will not be installed, you can manually do so later by calling install. Defaults to true.
    • webExt <object>, optional, lets you overwrite the parameters that get passed into web-ext.cmd.build
    • fxOptions firefox.Options, optional, a firefox.Options that will be passed to the webdriver

Returns a Promise that resolves with an initialized WebExtensionsGeckodriver instance in case of success, notably with the following properties:

  • geckodriver, <object>, a new selenium-webdriver/firefox instance with previously loaded geckodriver
  • install, <function>, returns a Promise that resolves when installing is finished, accepts an options <object>:
    • extensionPath, <string>, optional, path to something that installAddon can handle. Defaults to the web-ext build extensionPath.
    • temporary, <boolean>, optional, whether the WebExt should be installed temporary. Defaults to true.
  • internalUUID, <function>, returns a Promise that resolves to the Internal UUID of the installed extension
  • uninstall, <function>, returns a Promise that resolves when uninstalling is finished, accepts an optional extensions id as <string>

Exported property: webdriver

Return value of require('selenium-webdriver')

Exported property: firefox

Return value of require('selenium-webdriver/firefox')

Travis Configuration

dist: xenial
services:
  - xvfb

language: node_js
addons:
  firefox: latest

node_js:
  - 'lts/*'

Headless Example

const webExtensionsGeckoDriver = require('webextensions-geckodriver');

const {firefox} = webExtensionsGeckoDriver;
// or equivalently:
//   const firefox = require('selenium-webdriver/firefox')

const fxOptions = new firefox.Options()
  .headless()
  .windowSize({height: 1080, width: 1920}) // If you rely on viewport size

webExtensionsGeckoDriver(manifestPath, {fxOptions})

JSDOM

If you're looking for a way to test WebExtensions with JSDOM then webextensions-jsdom might be for you.

Credits

Thanks to Standard8 for the original work in example-webextension.

webextensions-geckodriver's People

Contributors

stoically avatar cmcaine avatar maxxcrawford avatar

Stargazers

Maciej Mionskowski avatar Danny Colin avatar Adam Sanderson avatar Wumpus avatar Guillem CANAL avatar Luiz Gonzaga dos Santos Filho avatar John Jones avatar Juraj Mäsiar avatar Shin'ya Ueoka avatar Anton Vilhelm Ásgeirsson avatar Martin Giger avatar Tomislav Jovanovic avatar jes avatar

Watchers

James Cloos avatar Anton Vilhelm Ásgeirsson avatar  avatar Wumpus avatar

webextensions-geckodriver's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.