Skip to content
Github mirror of "mediawiki/selenium" - our actual code is hosted with Gerrit (please see for contributing
Ruby Cucumber
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
spec Never show firstrun pages in Firefox
.ruby-gemset Corrected Style/LeadingCommentSpace RuboCop offenses
.ruby-version Corrected Style/LeadingCommentSpace RuboCop offenses
Rakefile Release patch version 1.6.2
mediawiki_selenium.gemspec Login helper for fast API-based authentication


MediaWiki-Selenium is a Ruby framework for the implementation and execution of acceptance tests against MediaWiki installations. It is comprised of a number of core dependencies and native APIs that help you describe the expected behavior of your MediaWiki-related features, and drive cross-browser simulations to ensure the correctness of your implementation.

Core Dependencies

  • Cucumber provides the natural Gherkin language used to describe application features, a basic API for binding that natural language to step definitions written in Ruby, and a test runner for executing the suite.

  • PageObject helps you to implement PageObject patterns within your test suite that better encapsulate the expected structure and mechanics of your application's UI.

  • Watir and Selenium for driving browser sessions.

  • RSpec for asserting expectations of scenario outcomes.


Ruby 1.9 or above is required, 2.1 is recommended. The easiest way to install it is with RVM or rbenv on Linux/Unix/OS X, and with RubyInstaller on Windows.

Create a Gemfile in the root of your MediaWiki-related project that specifies the version of mediawiki_selenium you wish to use (typically the latest version).

gem 'mediawiki_selenium', '~> 1.5.0'

Install the gem and its dependencies by running bundle install. (If Bundler is not yet installed, install it with gem install bundler, or sudo gem install bundler if you're using a system wide Ruby.)


Please read {} for documentation on how to upgrade from one major release to another.

Getting Started

Once the gem is installed, run mediawiki-selenium-init in your project's root directory to create a boilerplate configuration under tests/browser.

$ bundle exec mediawiki-selenium-init
    create  tests/browser
    create  tests/browser/environments.yml
    create  tests/browser/features/support/env.rb

Default configuration for various resources (wiki URLs, users, etc.) is typically loaded from an environments.yml YAML file in the current working directory. It should contain defaults for each environment in which the tests are expected to run, indexed by environment name. Double check that the generated file is suitable for how you expect your tests to be run, for example against Mediawiki-Vagrant for local development, or against at least the Beta Cluster for continuous integration.

For details on how environment configuration is loaded and used by step definitions, see the documentation for {MediawikiSelenium::Environment}.

Writing Tests

The ability to write effective and cruft-free tests will come with practice and greater familiarity with the underlying libraries. On, you'll find some helpful high-level documentation to get you started.

To see exactly which methods are available from within step definitions, see the documentation for {MediawikiSelenium::Environment}, {MediawikiSelenium::ApiHelper}, and {MediawikiSelenium::PageFactory}.

Running Tests

Execute your tests by running bundle exec cucumber from within the tests/browser directory.

By default, the entire suite is run which may take some time. If you wish to execute scenarios for just a single feature, you can provide the feature file as an argument.

bundle exec cucumber feature/some.feature

To run a single scenario, give the line number as well.

bundle exec cucumber feature/some.feature:11

The set of default configuration to use (see "Getting started") can be specified by the MEDIAWIKI_ENVIRONMENT environment variable, defined somewhere in your shell profile. If no value is set, an entry called default is loaded.

For example, if your environments.yml file looked something like this.

mw-vagrant-host: &default
  # ...

  # ...

  # ...

default: *default

Defining MEDIAWIKI_ENVIRONMENT=beta in your shell would tell MW-Selenium to use the configuration for beta above. Leaving it unset would use the entry called default which in this case points to mw-vagrant-host.

Firefox is the default browser, but you can specify a different one by setting BROWSER.

export BROWSER=phantomjs # Linux/Unix/Mac
set BROWSER=phantomjs # Windows Command Prompt
$env:BROWSER="internet_explorer" # Windows PowerShell

By default, the browser will close itself at the end of every scenario. If you want the browser to stay open, set KEEP_BROWSER_OPEN to true.

export KEEP_BROWSER_OPEN=true # Linux/Unix/Mac
set KEEP_BROWSER_OPEN=true # Windows Command Prompt
$env:KEEP_BROWSER_OPEN="true" # Windows PowerShell

Headless Mode

Headless operation can be useful when running tests in an environment where there's no GUI available, environments such as a continuous integration server, or a remote SSH session.

There are two basic ways to run in headless mode. The first is achieved by simply using an inherently headless browser such as PhantomJS.

BROWSER=phantomjs bundle exec cucumber ...

The second method is to specify a HEADLESS environment variable in combination with a non-headless browser. With this invocation MediaWiki-Selenium will start up a virtual display to which the browser can render. (Note that the underlying implementation relies on Xvfb and so is only supported on Linux.)

HEADLESS=true BROWSER=firefox bundle exec cucumber ...

Some additional options are available to further customize the headless behavior.

export HEADLESS=true

# Use a different display port (the default is 99)
HEADLESS_DISPLAY=100 bundle exec cucumber ...

# Don't reuse an already running xvfb (the default is to reuse)
HEADLESS_REUSE=false bundle exec cucumber ...

# Keep xvfb running after execution (the default is to kill it)
HEADLESS_DESTROY_AT_EXIT=false bundle exec cucumber ...

User Factory

Setting user_factory to true for an environment in your environments.yml will enable the {MediawikiSelenium::UserFactoryHelper} module. The module automatically creates accounts referenced in tests (calls to the user, password, or as_user methods) using the MW API, and randomizes the actual user names.

These randomized fixtures can greatly improve the atomicity/isolation of your scenarios, ensuring control over the initial user state (e.g. an edit count of 0) or allowing scenarios to run in parallel on the same MW installation.

Note that using this feature will result in a large number of accounts being created for each run. You'll typically want to enable this feature only for environments like CI (integration) or perhaps your local MW-Vagrant.

  user_factory: true
  # ...

  user_factory: true
  # ...


You can get screenshots on failures by setting the environment variable SCREENSHOT_FAILURES to true. Screenshots will be written under the screenshots directory relatively to working directory. The SCREENSHOT_FAILURES_PATH environment variable lets you override the destination path for screenshots. Example:

SCREENSHOT_FAILURES=true SCREENSHOT_FAILURES_PATH="/tmp/screenshots" bundle exec cucumber

Updating Your Gemfile

In your repository, the Gemfile specifies dependencies and Gemfile.lock defines the whole dependency tree. To update it simply run:

bundle update

It will fetch all dependencies and update the Gemfile.lock file, you can then commit back both files.


For a list of MediaWiki repositories that use this gem, see the Repositories with Ruby code page on



Releasing the gem

Step 1

When you're ready to cut a new release, increase the major/minor/patch version (the gem uses semantic versioning) and add release notes. Release notes should include:

  • What has changed
  • New features
  • Bug fixes
  • Possible incompatibilities

Update gem version in, and lib/mediawiki_selenium/version.rb. Add release notes to

Step 2

Push the commit to Gerrit. Wait for review and merge.

Step 3

When the commit is merged into master branch, fetch it and verify the commit is HEAD, for example:

$ git fetch
$ git log --oneline --decorate
123abcd (HEAD, origin/master, origin/HEAD, master, T108873) Release minor version 1.5.1

Step 4

Tag the commit, for example:

$ git fetch --tags
$ git log --oneline --decorate
123abcd (HEAD, origin/master, origin/HEAD, master, T108873) Release minor version 1.5.1
$ git tag 1.5.1 123abcd
$ git push --tags

Step 5

Build the gem, for example:

$ gem build mediawiki_selenium.gemspec
Successfully built RubyGem
Name: mediawiki_selenium
Version: 1.5.1
File: mediawiki_selenium-1.5.1.gem

The above gem assumes you have working Ruby and RubyGems.

Step 6

Push the gem to, for example:

$ gem push mediawiki_selenium-1.5.1.gem

The last step assumes you have account and are owner of the gem at the site.

Step 7

Announce the new release at QA mailing list.

Release notes

See {}.

Something went wrong with that request. Please try again.