Selenium Configuration

From MediaWiki.org
Jump to navigation Jump to search

This is detailed information for setting up the Selenium framework.

Enable Selenium on your test Wiki[edit]

Set the following in your test wiki's LocalSettings.php:

$wgEnableSelenium = true;

The tests runner is a maintenance script maintenance/tests/RunSeleniumTests.php
The next sections cover how you can tell the test runner about your selenium environment.

Configure Selenium using a configuration file[edit]

  • The easiest way is to point the test runner to your selenium configuration file through the command line option.
php RunSeleniumTests.php --seleniumConfig=../../selenium_settings.ini
Using Selenium Configuration file: ../../selenium_settings.ini
....
  • If the --seleniumConfig option is not found and in the absense of a hook, it looks for a global variable $wgSeleniumConfigFile that you can set in your LocalSettings.php
$wgSeleniumConfigFile = $IP . '/selenium_settings.ini';
php RunSeleniumTests.php 
No command line configuration file or configuration hook found.
....
Sample configuration to run on a local machine[edit]

A sample configuration is checked into maintenance/tests/selenium/selenium_settings.ini.sample

[SeleniumSettings]

; Set up the available browsers that Selenium can control.
browsers[firefox] 	= "*firefox"
browsers[iexplorer]     = "*iexploreproxy"
browsers[chrome] 	= "*chrome"

; The simple configurations above usually work on Linux, but Windows and
; Mac OS X hosts may need to specify a full path:
;browsers[firefox] = "*firefox /Applications/Firefox.app/Contents/MacOS/firefox-bin"
;browsers[firefox] = "*firefox C:\Program Files\Mozilla Firefox\firefox.exe"

host 				= "localhost"
port 				= "4444"
wikiUrl 			= "http://localhost/deployment"
username 			= "wikiuser"
userPassword 		        = "wikipass"
testBrowser 		        = "firefox"
startserver			=
stopserver			=
jUnitLogFile		        =
runAgainstGrid	                = false

; To let the test runner start and stop the selenium server, it needs the full
; path to selenium-server.jar from the selenium-remote-control package.
seleniumserverexecpath = "/opt/local/selenium-remote-control-1.0.3/selenium-server-1.0.3/selenium-server.jar"

[SeleniumTests]

testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/suites/SimpleSeleniumTestSuite.php"
testSuite[PagedTiffHandlerSeleniumTestSuite] = "extensions/PagedTiffHandler/selenium/PagedTiffHandlerTestSuite.php"

  • Hint: seleniumserverexecpath not yet implemented for Windows.
Sample configuration to run against a selenium grid[edit]

A sample configuration is checked into maintenance/tests/selenium/selenium_settings_grid.ini.sample

[SeleniumSettings]

host			= "grid.tesla.usability.wikimedia.org"
port			= "4444"
wikiUrl			= "http://208.80.152.253:5001"
username		= "wikiuser"
userPassword	        = "wikipass"
testBrowser		= "Safari on OS X Snow Leopard"
runAgainstGrid	        = true

[testSuite]

SimpleSeleniumTestSuite	= "maintenance/tests/selenium/suites/SimpleSeleniumTestSuite.php"
  • You don't need to define any browsers as this is done for you by the grid.
  • Available environments can be found at the grid console
    • Use the name under "Environment" as testBrowser value.
    • Use host:port as wikiUrl.
  • Make sure the option runAgainstGrid is set to true.

Configure Selenium using command line parameters (This may go away soon)[edit]

You can override parameters from the configuration file or the hook function using command line paranteres:

Usage: php RunSeleniumTests.php [--conf|--help|--host|--list-browsers|--port|--quiet|--seleniumConfig
                                |--testBrowser|--userPassword|--username|--verbose|--wikiUrl]

    conf : Location of LocalSettings.php, if not default
    help : Display this help message
    host : Host selenium server. Default: $wgServer . $wgScriptPath
    list-browsers : List the available browsers.
    port : Port used by selenium server. Default: 4444
    quiet : Whether to supress non-error output
    seleniumConfig : Location of the selenium config file. Default: empty
    testBrowser : The browser he used during testing. Default: firefox
    userPassword : The login password for running tests. Default: empty
    username : The login username for sunning tests. Default: empty
    verbose : Be noisier.
    wikiUrl : The Mediawiki installation to point to. Default: http://localhost

For example:

php RunSeleniumTests.php --wikiUrl='http://localhost/deployment' --username='WikiSysop' --userPassword='xxxxxx'

Configure Selenium using a Hook function[edit]

Another way to configure your selenium test instance is through a Hook - SeleniumSettings.

$wgHooks['SeleniumSettings'][] = 'MyCustomSeleniumTestConfigStatic::getSeleniumSettings';

You will need to add MyCustomSeleniumTestConfigStatic to the AutoLoader or your LocalSettings.php.

The 3 required parameters passed by reference are:

  • $seleniumSettings: An array containing the selenium configuration parameters as key value pairs> Possible keys are:
array (
  'host' => '<selenium server host>',
  'port' => '<selenium server port>',
  'wikiUrl' => '<the test wiki url>',
  'username' => '<the username if the tests require login>',
  'userPassword' => '<the user password if the tests require login>',
  'testBrowser' => '<the browser to use for testing>',
)
  • $seleniumBrowsers: Browsers available to the selenium server. For example:
array (
  'firefox' => '*firefox',
  'iexplorer' => '*iexploreproxy',
  'chrome' => '*chrome',
)
  • $seleniumTestSuites: Path to the test suites that the test runner will run. For example:
array (
  'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php',
  'MyExtensionTestSuite' => 'extensions/myextension/tests/selenium/MyExtensionTestSuite.php',
)