From 737a79092689e20bfcb0703c5ee08cfe50369e6d Mon Sep 17 00:00:00 2001 From: Markus Glaser Date: Fri, 28 May 2010 23:32:40 +0000 Subject: [PATCH] * Configuration of port (credits to Dan Nessett) * Moved LocalSeleniumSettings to selenium folder * Sample selenium settings file * Added Example test case --- maintenance/tests/RunSeleniumTests.php | 64 ++++++++++--------- .../selenium/LocalSeleniumSettings.php.sample | 51 +++++++++++++++ maintenance/tests/selenium/Selenium.php | 10 ++- .../tests/selenium/SimpleSeleniumTest.php | 31 +++++++++ 4 files changed, 122 insertions(+), 34 deletions(-) create mode 100644 maintenance/tests/selenium/LocalSeleniumSettings.php.sample create mode 100644 maintenance/tests/selenium/SimpleSeleniumTest.php diff --git a/maintenance/tests/RunSeleniumTests.php b/maintenance/tests/RunSeleniumTests.php index 6def620302..41b3044041 100644 --- a/maintenance/tests/RunSeleniumTests.php +++ b/maintenance/tests/RunSeleniumTests.php @@ -25,43 +25,45 @@ define( 'MEDIAWIKI', true ); define( 'SELENIUMTEST', true ); +// Here, you can override standard setting +if ( file_exists( 'selenium/LocalSeleniumSettings.php' ) ) { + include_once 'selenium/LocalSeleniumSettings.php'; +} else { + echo "You must provide local settings in LocalSeleniumSettings.php\n"; + die( -1 ); +} + // Command line only -$wgSeleniumTestsRunMode = 'cli'; if ( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) { - echo 'Must be run from the command line.'; + echo "Must be run from the command line.\n"; die( -1 ); } -// include path and installation instructions - -// URL: http://localhost/tests/RunSeleniumTests.php -// set_include_path( get_include_path() . PATH_SEPARATOR . './PEAR/' ); - -// Hostname of selenium server -$wgSeleniumTestsSeleniumHost = 'http://localhost'; -// URL of the wiki to be tested. -$wgSeleniumTestsWikiUrl = 'http://localhost'; - -// Wiki login. Used by Selenium to log onto the wiki -$wgSeleniumTestsWikiUser = 'WikiSysop'; -$wgSeleniumTestsWikiPassword = 'password'; - -// Common browsers on Windows platform -// 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['firefox'] = '*firefox c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'; -$wgSeleniumTestsBrowsers['firefox'] = '*chrome c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'; -$wgSeleniumTestsBrowsers['iexplorer'] = '*iexploreproxy'; - -// Actually, use this browser -$wgSeleniumTestsUseBrowser = 'firefox'; +// Get command line parameters +if ( $wgSeleniumTestsRunMode == 'cli' ) { + require_once( dirname( __FILE__ ) . '/../commandLine.inc' ); + if ( isset( $options['help'] ) ) { + echo << Port used by selenium server to accept commands + --help Show this help message +ENDS; + exit( 0 ); + } + + if ( isset( $options['port'] ) ) { + $wgSeleniumServerPort = (int) $options['port']; + } +} // requires PHPUnit 3.4 require_once 'Testing/Selenium.php'; require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; -// include uiTestsuite +// include seleniumTestsuite require_once 'selenium/SeleniumTestHTMLLogger.php'; require_once 'selenium/SeleniumTestConsoleLogger.php'; require_once 'selenium/SeleniumTestListener.php'; @@ -83,12 +85,12 @@ $result->addListener( new SeleniumTestListener( $logger ) ); $wgSeleniumTestSuites = array(); +// include tests // Todo: include automatically -# include_once ''; - -// Here, you can override standard setting -if ( file_exists( 'LocalSeleniumSettings.php' ) ) { - include_once 'LocalSeleniumSettings.php'; +if ( is_array( $wgSeleniumTestIncludes ) ) { + foreach ( $wgSeleniumTestIncludes as $include ) { + include_once $include; + } } // run tests diff --git a/maintenance/tests/selenium/LocalSeleniumSettings.php.sample b/maintenance/tests/selenium/LocalSeleniumSettings.php.sample new file mode 100644 index 0000000000..a4dfeeaeba --- /dev/null +++ b/maintenance/tests/selenium/LocalSeleniumSettings.php.sample @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/maintenance/tests/selenium/Selenium.php b/maintenance/tests/selenium/Selenium.php index d6cdff76ff..57d9982387 100644 --- a/maintenance/tests/selenium/Selenium.php +++ b/maintenance/tests/selenium/Selenium.php @@ -15,9 +15,13 @@ class Selenium extends Testing_Selenium { public static function getInstance() { global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser; + global $wgSeleniumTestsWikiUrl, $wgSeleniumServerPort; if ( null === self::$_instance ) { - self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost ); - } + self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], + $wgSeleniumTestsWikiUrl, + $wgSeleniumTestsSeleniumHost, + $wgSeleniumServerPort ); + } return self::$_instance; } @@ -39,7 +43,7 @@ class Selenium extends Testing_Selenium { $this->type( 'wpName1', $wgSeleniumTestsWikiUser ); $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword ); $this->click( "//input[@id='wpLoginAttempt']" ); - $value = $this->doCommand( 'assertTitle', array( 'Anmeldung erfolgreich*' ) ); + $value = $this->doCommand( 'assertTitle', array( 'Login successful*' ) ); } public function loadPage( $title, $action ) { diff --git a/maintenance/tests/selenium/SimpleSeleniumTest.php b/maintenance/tests/selenium/SimpleSeleniumTest.php new file mode 100644 index 0000000000..c002ecfe8f --- /dev/null +++ b/maintenance/tests/selenium/SimpleSeleniumTest.php @@ -0,0 +1,31 @@ +addTest(new SimpleSeleniumTest()); + +class SimpleSeleniumTest extends SeleniumTestCase +{ + public $name = "Basic selenium test"; + + public function runTest() + { + global $wgSeleniumTestsWikiUrl; + $this->open($wgSeleniumTestsWikiUrl.'/index.php?title=Selenium&action=edit'); + $this->type("wpTextbox1", "This is a basic test"); + $this->click("wpPreview"); + $this->waitForPageToLoad(10000); + + // check result + $source = $this->getText("//div[@id='wikiPreview']/p"); + $correct = strstr($source, "This is a basic test"); + $this->assertEquals($correct, true); + + } + +} \ No newline at end of file -- 2.20.1