From: Ryan Lane Date: Fri, 30 Apr 2010 20:45:52 +0000 (+0000) Subject: Initial commit of the Selenium framework X-Git-Tag: 1.31.0-rc.0~36976 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=74d34f58ddb1c464649872a9fe8d60d6bf0d4828;hp=1cbc59dac8a2e4c74d5d5781ee231709a629dcf4;p=lhc%2Fweb%2Fwiklou.git Initial commit of the Selenium framework --- diff --git a/maintenance/tests/RunSeleniumTests.php b/maintenance/tests/RunSeleniumTests.php new file mode 100644 index 0000000000..bae7234c45 --- /dev/null +++ b/maintenance/tests/RunSeleniumTests.php @@ -0,0 +1,93 @@ +addListener(new SeleniumTestListener($logger)); + + +$wgSeleniumTestSuites = array(); + +// Todo: include automatically +#include_once ''; + +// Here, you can override standard setting +if (file_exists('LocalSeleniumSettings.php')) +{ + include_once 'LocalSeleniumSettings.php'; +} + +// run tests +foreach ($wgSeleniumTestSuites as $suite) + $suite->run($result); +?> diff --git a/maintenance/tests/selenium/Selenium.php b/maintenance/tests/selenium/Selenium.php new file mode 100644 index 0000000000..b4bcc8ead8 --- /dev/null +++ b/maintenance/tests/selenium/Selenium.php @@ -0,0 +1,60 @@ +isStarted = true; + } + + public function stop() + { + parent::stop(); + $this->isStarted = false; + } + + public function login() + { + global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword, $wgSeleniumTestsWikiUrl; + + $this->open($wgSeleniumTestsWikiUrl.'/index.php?title=Special:Userlogin'); + $this->type("wpName1", $wgSeleniumTestsWikiUser); + $this->type("wpPassword1", $wgSeleniumTestsWikiPassword); + $this->click("//input[@id='wpLoginAttempt']"); + $value = $this->doCommand('assertTitle', array('Anmeldung erfolgreich*')); + } + + public function loadPage($title, $action) + { + global $wgSeleniumTestsWikiUrl; + $this->open($wgSeleniumTestsWikiUrl.'/index.php?title='.$title.'&action='.$action); + } + + // Prevent external cloning + protected function __clone() {} + // Prevent external construction + //protected function __construct() {} +} diff --git a/maintenance/tests/selenium/SeleniumTestCase.php b/maintenance/tests/selenium/SeleniumTestCase.php new file mode 100644 index 0000000000..6aadbfaa2d --- /dev/null +++ b/maintenance/tests/selenium/SeleniumTestCase.php @@ -0,0 +1,43 @@ +selenium = Selenium::getInstance(); + //print_r($this->suite); + } + + public function tearDown() + { + + } + + public function __call($method, $args) + { + return call_user_func_array (array($this->selenium, $method), $args); + } + + public function assertSeleniumAttributeEquals($attribute, $value) + { + $attr = $this->getAttribute($attribute); + $this->assertEquals($attr, $value); + } + + public function assertSeleniumHTMLContains($element, $text) + { + $innerHTML = $this->getText($element); + //or assertContains + $this->assertRegExp("/$text/", $innerHTML ); + } + +} + +?> diff --git a/maintenance/tests/selenium/SeleniumTestConsoleLogger.php b/maintenance/tests/selenium/SeleniumTestConsoleLogger.php new file mode 100644 index 0000000000..7473ece388 --- /dev/null +++ b/maintenance/tests/selenium/SeleniumTestConsoleLogger.php @@ -0,0 +1,29 @@ +'; + $out .= htmlentities($message); + //if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= ''; + if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= "\n"; + + echo $out; + } +} \ No newline at end of file diff --git a/maintenance/tests/selenium/SeleniumTestHTMLLogger.php b/maintenance/tests/selenium/SeleniumTestHTMLLogger.php new file mode 100644 index 0000000000..6b9c3a6c9d --- /dev/null +++ b/maintenance/tests/selenium/SeleniumTestHTMLLogger.php @@ -0,0 +1,43 @@ + + pre { + overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */ + white-space: pre-wrap; /* css-3 */ + white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + /* width: 99%; */ + word-wrap: break-word; /* Internet Explorer 5.5+ */ + } + '; + + + } + + public function write($message, $mode = false) + { + $out .= ''; + if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= ''; + $out .= htmlentities($message); + if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= ''; + if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= '
'; + + echo $out; + } +} \ No newline at end of file diff --git a/maintenance/tests/selenium/SeleniumTestListener.php b/maintenance/tests/selenium/SeleniumTestListener.php new file mode 100644 index 0000000000..d4675899dc --- /dev/null +++ b/maintenance/tests/selenium/SeleniumTestListener.php @@ -0,0 +1,74 @@ +logger = $loggerInstance; + } + + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->logger->write("Error: ".$e->getMessage()); + $this->tests_failed++; + } + + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->logger->write("Failed: ".$e->getMessage()); + $this->tests_failed++; + + } + + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->logger->write("Incomplete."); + $this->tests_failed++; + } + + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->logger->write("Skipped."); + $this->tests_failed++; + } + + public function startTest(PHPUnit_Framework_Test $test) + { + $this->logger->write("Testing ".$test->getName()." ... ", MW_TESTLOGGER_CONTINUE_LINE); + } + + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if (!$test->hasFailed()) + { + $this->logger->write("OK", MW_TESTLOGGER_RESULT_OK); + $this->tests_ok++; + } + } + + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->logger->write("Testsuite ".$suite->getName()." started."); + $this->tests_ok = 0; + } + + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->logger->write("Testsuite ".$suite->getName()." ended. OK: ".$this->tests_ok." Failed: ".$this->tests_failed); + + } + + public function statusMessage($message) + { + $this->logger->write($message); + } +} + diff --git a/maintenance/tests/selenium/SeleniumTestSuite.php b/maintenance/tests/selenium/SeleniumTestSuite.php new file mode 100644 index 0000000000..b7456f150c --- /dev/null +++ b/maintenance/tests/selenium/SeleniumTestSuite.php @@ -0,0 +1,40 @@ +selenium = Selenium::getInstance(); + $this->selenium->start(); + $this->login(); + //$this->loadPage('Testpage', 'edit'); + } + + public function tearDown() + { + $this->selenium->stop(); + } + + public function login() + { + $this->selenium->login(); + } + + public function loadPage($title, $action) + { + $this->selenium->loadPage($title, $action); + } +} +