Selenium/Ruby/Shared features

From mediawiki.org

This is a list of features provided by the mediawiki_selenium RubyGem that are available to all browser tests in all repos. See Quality Assurance/Browser testing/Writing tests for an introduction to writing tests.


Login[edit]

Logs the user in on the wiki specified by the environment variable MEDIAWIKI_URL

Usage[edit]

In any Scenario in any Feature, just use

 Given I am logged in

and the shared login step will use the environment variables MEDIAWIKI_USER and MEDIAWIKI_PASSWORD to login at the target wiki.

Notes[edit]

Login is accomplished as thoroughly as possible:

  • in order to avoid missed clicks, the script fires an "onfocus" event on the login button before clicking
  • in order to confirm login, the script checks for the existence of a link to "Special:UserLogout" in order to proceed. This check works in all languages for all wikis

Random page[edit]

Sends the script to a random page in the target wiki

Usage[edit]

In any Scenario in any Feature, just use

 Given/When I am am at a random page

Notes[edit]

uses Special:Random in the target wiki

Reset preferences[edit]

Resets all of the test user's preferences to default settings.

Usage[edit]

In any Scenario in any Feature, just use

 Given/When I have reset my preferences

Notes[edit]

This feature has the potential to interfere with other tests that rely on particular preferences being set in a particular way. Make certain that this feature is used only for test users whose preference settings are irrelevant for other work.

ResourceLoader errors[edit]

After loading any page, this step will check for ResourceLoader errors and report any modules that have errors and any modules that are missing.

Usage[edit]

In any Scenario in any Feature, just use

 Given/When/Then page has no ResourceLoader errors

Notes[edit]

This is a pure javascript check and does not manipulate any aspect of browser function.

Upload file[edit]

Steps to upload valid or invalid media files via the shared interface in both Firefox and Chrome

Usage[edit]

In any Scenario in any Feature, just use

 When upload file <filename>

to upload a valid PNG image file

and

 When upload bogus file <filename>

to upload an invalid empty file

Notes[edit]

As of 2014 April this is valid only the MobileFrontend and UploadWizard repositories. The steps are shared, but each repo right now has it's own version of the UploadPage page object. This is Bug 63833


Create page at run time via API[edit]

Creates a page with particular title and text in the target wiki at runtime.

In the target wiki:

  • if no page with this title exists, the page will be created with the specified content
  • if a page with this title exists but the contents of the page differ from what is in the API call, the existing page will be updated with the contents of the API call by means of a normal revision, which will appear in the history of the page.
  • if a page with this title exists and the contents of the page are identical to what is in the API call, the existing page is not changed in any way, and no additional revisions are created. This is a no-op.

Usage[edit]

In the steps for any Scenario do

Given(/^I create some page with some content$/) do
  on(APIPage).create "page title", "page contents"
end

Note the creative possibilities:

  • to create a page in the target wiki with a quasi-unique title that the running Scenario will be able to find and use in the course of the test:
Given(/^I create a random page using the API$/) do
  on(APIPage).create @random_string, @random_string
end
  • to guarantee that a particular page in the target wiki will have particular content, and then navigate to that page:
Given(/^I go to a page that has references$/) do
  wikitext = "MobileFrontend is a 
MediaWiki extension.<ref>[http://mediawiki.org/wiki/Extension:MobileFrontend Extension:MobileFrontend]</ref>

==References==
<references />"

  on(APIPage).create "Selenium References test page", wikitext
  step 'I am on the "Selenium References test page" page'
end

Protect[edit]

sets the level of protection to

edit=sysop|move=sysop


Usage[edit]

on(APIPage).protect "Title of page to be protected", "Reason for protection"

Notes[edit]

APIPage features rely on an environment variable MEDIAWIKI_API_URL. Before the test runs, do for example:

 export MEDIAWIKI_API_URL=http://en.wikipedia.beta.wmflabs.org/w/api.php

The test will abort immediately if it calls (ApiPage).create and the MEDIAWIKI_API_URL env var is not in place.

Also note that the user identified by the environment variables MEDIAWIKI_USER and MEDIAWIKI_PASSWORD must have proper permissions to manipulate pages on the target wiki via the API in order to use this feature.