* Remove $wg*Selenium* globals as they are only used for testing.
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 4 Sep 2010 00:58:57 +0000 (00:58 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 4 Sep 2010 00:58:57 +0000 (00:58 +0000)
* mglaser said the SpecialSelenium page wasn't needed so I'm removing it – I suggest its functionality be put in an extension if needed.
* Add verbose option (requires patch to Testing_Selenium) to RunSeleniumTests.
* TODO: add .ini file to hold local configuration
* TODO: add ability to sniff available browsers from Grid server instead of hard-coding.

includes/DefaultSettings.php
includes/SpecialPage.php
includes/specials/SpecialSelenium.php [deleted file]
maintenance/tests/RunSeleniumTests.php
maintenance/tests/selenium/Selenium.php

index aa38e90..b105530 100644 (file)
@@ -3719,50 +3719,6 @@ $wgParserTestFiles = array(
  */
 $wgParserTestRemote = false;
 
-/**
- * Enable Selenium test framework.
- * This enables maintenance/tests/RunSeleniumTests.php and [[Special:Selenium]].
- */
-$wgEnableSelenium = false;
-
-/** List of Selenium test suites. These must be registered with the autoloader. */
-$wgSeleniumTestSuites = array(
-       'SimpleSeleniumTestSuite'
-);
-
-
-/** Hostname of selenium server */
-$wgSeleniumTestsSeleniumHost = 'localhost';
-
-/** URL of the wiki to be tested. By default, the local wiki is used. */
-$wgSeleniumTestsWikiUrl = false;
-
-/** Port used by selenium server. */
-$wgSeleniumServerPort = 4444;
-
-/** Wiki login username. Used by Selenium to log onto the wiki. */
-$wgSeleniumTestsWikiUser      = 'Wikiuser';
-
-/** Wiki login password. Used by Selenium to log onto the wiki. */
-$wgSeleniumTestsWikiPassword  = '';
-
-/**
- * Common browsers on Windows platform. Modify for other platforms or
- * other Windows browsers.
- * Use the *chrome handler in order to be able to test file uploads.
- * Further solution suggestions: http://www.brokenbuild.com/blog/2007/06/07/testing-file-uploads-with-selenium-rc-and-firefoxor-reducing-javascript-security-in-firefox-for-fun-and-profit/
- */
-$wgSeleniumTestsBrowsers = array(
-       'firefox' => '*firefox /usr/bin/firefox',
-       'iexplorer' => '*iexploreproxy',
-       'opera' => '*chrome /usr/bin/opera',
-);
-
-/** Actually, use this browser */
-$wgSeleniumTestsUseBrowser = 'firefox';
-
-
-
 /** @} */ # end of profiling, testing and debugging }
 
 /************************************************************************//**
index e3174db..fbbf7a2 100644 (file)
@@ -207,7 +207,6 @@ class SpecialPage {
        static function initList() {
                global $wgSpecialPages;
                global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
-               global $wgEnableSelenium;
 
                if ( self::$mListInitialised ) {
                        return;
@@ -230,10 +229,6 @@ class SpecialPage {
                        self::$mList['Invalidateemail'] = 'EmailInvalidation';
                }
 
-               if ( $wgEnableSelenium ) {
-                       self::$mList['Selenium'] = 'SpecialSelenium';
-               }
-
                # Add extension special pages
                self::$mList = array_merge( self::$mList, $wgSpecialPages );
 
diff --git a/includes/specials/SpecialSelenium.php b/includes/specials/SpecialSelenium.php
deleted file mode 100644 (file)
index 4a7a0d1..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * Implements Special:Selenium
- *
- * @file
- * @ingroup SpecialPage
- * @todo Remove this feature
- */
-
-/**
- * @ingroup SpecialPage
- */
-class SpecialSelenium extends SpecialPage {
-       function __construct() {
-               parent::__construct( 'Selenium', 'selenium', false );
-       }
-
-       function getDescription() {
-               return 'Selenium';
-       }
-
-       function execute( $par ) {
-               global $wgUser, $wgOut, $wgEnableSelenium, $wgRequest;
-
-               if ( !$wgEnableSelenium ) {
-                       throw new MWException( 
-                               'Selenium special page invoked when it should not be registered!' );
-               }
-
-               $this->setHeaders();
-               if ( !$this->userCanExecute( $wgUser ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
-
-               if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
-                       $this->runTests();
-               }
-               $wgOut->addHTML( 
-                       Html::openElement( 'form', array(
-                               'method' => 'POST',
-                               'action' => $this->getTitle()->getLocalUrl(),
-                       ) ) .
-                       Html::input( 'submit', 'Run tests', 'submit' ) .
-                       Html::hidden( 'token', $wgUser->editToken() ) .
-                       '</form>'
-               );
-       }
-
-       function runTests() {
-               global $wgSeleniumTestSuites, $wgOut, $wgSeleniumLogger;
-               SeleniumLoader::load();
-
-               $result = new PHPUnit_Framework_TestResult;
-               $wgSeleniumLogger = new SeleniumTestHTMLLogger;
-               $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
-               //$wgSeleniumLogger->setHeaders();
-
-               // run tests
-               $wgOut->addHTML( '<div class="selenium">' );
-               
-               // for some really strange reason, foreach doesn't work here. It produces an infinite loop,
-               // executing only the first test suite.
-               for ( $i = 0; $i < count( $wgSeleniumTestSuites ); $i++ ) {
-                       $suite = new $wgSeleniumTestSuites[$i];
-                       $suite->addTests();
-                       $suite->run( $result );
-               }
-               $wgOut->addHTML( '</div>' );
-       }
-}
-
index 935d9a4..58fbfcd 100644 (file)
 define( 'SELENIUMTEST', true );
 
 require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" );
+require_once( 'PHPUnit/Framework.php' );
+require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' );
+
 
 class SeleniumTester extends Maintenance {
+       protected $selenium;
+
        public function __construct() {
                parent::__construct();
 
@@ -45,27 +50,25 @@ class SeleniumTester extends Maintenance {
        }
 
        public function listBrowsers() {
-               global $wgSeleniumTestsBrowsers;
-
                $desc = "Available browsers:\n";
-               foreach ($wgSeleniumTestsBrowsers as $k => $v) {
+
+               $sel = new Selenium;
+               foreach ($sel->setupBrowsers() as $k => $v) {
                        $desc .= "  $k => $v\n";
                }
 
                echo $desc;
        }
 
-       protected function runTests( $verbose = false ) {
-               global $wgSeleniumLogger, $wgSeleniumTestSuites;
+       protected function getTestSuites() {
+               return array( 'SimpleSeleniumTestSuite' );
+       }
 
-               require_once( 'Testing/Selenium.php' );
-               require_once( 'PHPUnit/Framework.php' );
-               require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' );
+       protected function runTests( ) {
                $result = new PHPUnit_Framework_TestResult;
-               $wgSeleniumLogger = new SeleniumTestConsoleLogger;
-               $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
+               $result->addListener( new SeleniumTestListener( $this->selenium->getLogger() ) );
 
-               foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
+               foreach ( $this->getTestSuites() as $testSuiteName ) {
                        $suite = new $testSuiteName;
                        $suite->addTests();
                        try {
@@ -77,20 +80,29 @@ class SeleniumTester extends Maintenance {
        }
 
        public function execute() {
-               global $wgSeleniumServerPort, $wgSeleniumTestsSeleniumHost,
-                       $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
+               global $wgServer, $wgScriptPath;
+
+               /**
+                * @todo Add an alternative where settings are read from an INI file.
+                */
+               $this->selenium = new Selenium( );
+               $this->selenium->setUrl( $this->getOption( 'url', $wgServer . $wgScriptPath ) );
+               $this->selenium->setBrowser( $this->getOption( 'browser', 'firefox' ) );
+               $this->selenium->setPort( $this->getOption( 'port', 4444 ) );
+               $this->selenium->setHost( $this->getOption( 'host', 'localhost' ) );
+               $this->selenium->setUser( $this->getOption( 'user', 'WikiSysop' ) );
+               $this->selenium->setPass( $this->getOption( 'pass', 'Password' ) );
+               $this->selenium->setVerbose( $this->hasOption( 'verbose' ) );
 
                if( $this->hasOption( 'list-browsers' ) ) {
                        $this->listBrowsers();
                        exit(0);
                }
 
-               $wgSeleniumServerPort = $this->getOption( 'port', 4444 );
-               $wgSeleniumTestsSeleniumHost = $this->getOption( 'host', 'localhost' );
-               $wgSeleniumTestsWikiUrl = $this->getOption( 'url', $wgServer . $wgScriptPath );
-               $wgSeleniumTestsUseBrowser = $this->getOption( 'browser', 'firefox' );
+               $logger = new SeleniumTestConsoleLogger;
+               $this->selenium->setLogger( $logger );
 
-               $this->runTests( $this->hasOption( 'verbose' ) );
+               $this->runTests( );
        }
 }
 
index 4bd54ba..de7d9e0 100644 (file)
@@ -4,49 +4,76 @@
  * This is implemented as a singleton.
  */
 
-class Selenium extends Testing_Selenium {
+require( 'Testing/Selenium.php' );
+class Selenium {
        protected static $_instance = null;
        public $isStarted = false;
+       public $tester;
 
-       public static function getInstance() {
-               global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
-               global $wgSeleniumServerPort, $wgSeleniumLogger;
+       protected $port;
+       protected $host;
+       protected $browser;
+       protected $browsers;
+       protected $logger;
+       protected $user;
+       protected $pass;
+       protected $timeout = 30000;
+       protected $verbose;
+
+       /**
+        * @todo this shouldn't have to be static
+        */
+       static protected $url;
 
+       /**
+        * Override parent
+        */
+       public function __construct() {
+               /**
+                * @todo this is an ugly hack to make information available to
+                * other tests.  It should be fixed.
+                */
                if ( null === self::$_instance ) {
-                       $wgSeleniumLogger->write( "Browser: " . $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser] );
-                       self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser],
-                                                       self::getBaseUrl(),
-                                                       $wgSeleniumTestsSeleniumHost,
-                                                       $wgSeleniumServerPort );
+                       self::$_instance = $this;
+               } else {
+                       throw new MWException("Already have one Selenium instance.");
                }
-               return self::$_instance;
        }
 
        public function start() {
-               parent::start();
+               $this->tester = new Testing_Selenium( $this->browser, self::$url, $this->host,
+                       $this->port, $this->timeout );
+               if ( method_exists( $this->tester, "setVerbose" ) ) $this->tester->setVerbose( $this->verbose );
+
+               $this->tester->start();
                $this->isStarted = true;
        }
 
        public function stop() {
-               parent::stop();
+               $this->tester->stop();
+               $this->tester = null;
                $this->isStarted = false;
        }
 
-       static function getBaseUrl() {
-               global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
-               if ( $wgSeleniumTestsWikiUrl ) {
-                       return $wgSeleniumTestsWikiUrl;
-               } else {
-                       return $wgServer . $wgScriptPath;
+       protected function setupBrowsers() {
+               /**
+                * @todo This needs to be replaced with something not hard
+                * coded. This would be entries in a .ini file or
+                * screen-scraping
+                * http://grid.tesla.usability.wikimedia.org:4444/console for
+                * example.
+                */
+               return array(
+                       'firefox' => 'Firefox 3.5 on Linux',
+                       'iexplorer' => '*iexploreproxy',
+                       'chrome' => '*googlechrome',
+               );
                }
-       }
 
        public function login() {
-               global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword;
-
-               $this->open( self::getBaseUrl() . '/index.php?title=Special:Userlogin' );
-               $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
-               $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
+               $this->open( self::$url . '/index.php?title=Special:Userlogin' );
+               $this->type( 'wpName1', $this->user );
+               $this->type( 'wpPassword1', $this->pass );
                $this->click( "//input[@id='wpLoginAttempt']" );
                $this->waitForPageToLoad(5000);
                //after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
@@ -57,18 +84,71 @@ class Selenium extends Testing_Selenium {
                
        }
 
+       public static function getInstance() {
+               if ( null === self::$_instance ) {
+                       throw new MWException( "No instance set yet" );
+               }
+
+               return self::$_instance;
+       }
+
        public function loadPage( $title, $action ) {
-               $this->open( self::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action );
+               $this->open( self::$url . '/index.php?title=' . $title . '&action=' . $action );
        }
        
-       /*
-        * Log to console or html depending on the value of $wgSeleniumTestsRunMode
-        */
+       public function setLogger( $logger ) {
+               $this->logger = $logger;
+       }
+
+       public function getLogger( ) {
+               return $this->logger;
+       }
+
        public function log( $message ) {
-               global $wgSeleniumLogger;
-               $wgSeleniumLogger->write( $message );
+               $this->logger->write( $message );
        }
        
+       public function setUrl( $url ) {
+               self::$url = $url;
+       }
+
+       static public function getUrl() {
+               return self::$url;
+       }
+
+       public function setPort( $port ) {
+               $this->port = $port;
+       }
+
+       public function setUser( $user ) {
+               $this->user = $user;
+       }
+
+       public function setPass( $pass ) {
+               $this->pass = $pass;
+       }
+
+       public function setHost( $host ) {
+               $this->host = $host;
+       }
+
+       public function setVerbose( $verbose ) {
+               $this->verbose = $verbose;
+       }
+
+       public function setBrowser( $b ) {
+               $browsers = $this->setupBrowsers();
+               if ( !isset( $browsers[$b] ) ) {
+                       throw new MWException( "Invalid Browser: $b.\n" );
+               }
+               $this->browser = $browsers[$b];
+       }
+
+       public function __call( $name, $args ) {
+               $t = call_user_func_array( array( $this->tester, $name), $args );
+               return $t;
+       }
+
        // Prevent external cloning
        protected function __clone() { }
        // Prevent external construction