diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 2d65b67245..bbfb318c93 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -11,17 +11,12 @@
host="127.0.0.1"
port="4444"
timeout="30000"/>
-
-
+
diff --git a/test/AllSeleniumTests.php b/test/AllSeleniumTests.php
new file mode 100644
index 0000000000..89e83c64a7
--- /dev/null
+++ b/test/AllSeleniumTests.php
@@ -0,0 +1,38 @@
+addTestSuite('PmaSeleniumLoginTest');
+ //$suite->addTestSuite('PmaSeleniumXssTest');
+ //$suite->addTestSuite('PmaSeleniumPrivilegesTest');
+ return $suite;
+ }
+}
+?>
diff --git a/test/selenium/Helper.php b/test/selenium/Helper.php
new file mode 100644
index 0000000000..0d016532cd
--- /dev/null
+++ b/test/selenium/Helper.php
@@ -0,0 +1,32 @@
+isElementPresent('//*[@id="serverinfo"]/a[1]');
+ }
+
+ public static function logOutIfLoggedIn($selenium) {
+ if (self::isLoggedIn($selenium)) {
+ $selenium->selectFrame("frame_navigation");
+ $selenium->clickAndWait("css=img.icon.ic_b_home");
+ }
+ }
+
+ public static function getBrowserString() {
+ $browserString = self::$config->getCurrentBrowser();
+ return $browserString;
+ }
+
+}
+
+?>
diff --git a/test/selenium/PmaSeleniumLoginTest.php b/test/selenium/PmaSeleniumLoginTest.php
index 5e36564d69..7728e2d862 100644
--- a/test/selenium/PmaSeleniumLoginTest.php
+++ b/test/selenium/PmaSeleniumLoginTest.php
@@ -1,4 +1,5 @@
setBrowser(Helper::getBrowserString());
+ $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
+ }
- public function testLogin()
- {
- $this->doLogin();
+ public function testSuccessfulLogin() {
+ $log = new PmaSeleniumTestCase($this);
+ $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD);
+ $this->assertTrue($log->isSuccessLogin());
+ Helper::logOutIfLoggedIn($this);
+ }
- // Check if login error happend
- if ($this->isElementPresent("//html/body/div/div[@class='error']")) {
- $this->fail($this->getText("//html/body/div/div[@class='error']"));
- }
+ public function testLoginWithWrongPassword() {
+ $log = new PmaSeleniumTestCase($this);
+ $log->login("Admin", "Admin");
+ $this->assertTrue($log->isUnsuccessLogin());
+ Helper::logOutIfLoggedIn($this);
+ }
- // Check server info heder is present //*[@id="serverinfo"]
- for ($second = 0;; $second++) {
- if ($second >= 60)
- $this->fail("Timeout waiting main page to load!");
- try {
- if ($this->isElementPresent("//*[@id=\"serverinfo\"]"))
- break;
- } catch (Exception $e) {
- $this->fail("Exception: ".$e->getMessage());
- }
- sleep(1);
- }
-
- }
}
+
?>
diff --git a/test/selenium/PmaSeleniumTestCase.php b/test/selenium/PmaSeleniumTestCase.php
index 669dc8dbb7..9b6b982c81 100644
--- a/test/selenium/PmaSeleniumTestCase.php
+++ b/test/selenium/PmaSeleniumTestCase.php
@@ -7,65 +7,63 @@
* @group Selenium
*/
-// Optionally add the php-client-driver to your include path
-//set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
-
-// Include the main phpMyAdmin user config
-// currently only $cfg['Test'] is used
-require_once 'config.sample.inc.php';
-
-
-
-class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
+class PmaSeleniumTestCase
{
- protected $selenium;
- protected $cfg;
+ private $txtUsername;
+ private $txtPassword;
+ private $btnLogin;
+ private $selenium;
+ private $config;
- protected $captureScreenshotOnFailure = true;
- protected $screenshotPath = '/var/www/screenshots';
- protected $screenshotUrl = 'http://localhost/screenshots';
+ public function __construct($selenium) {
+ $this->txtUsername = 'input_username';
+ $this->txtPassword = 'input_password';
+ $this->btnLogin = 'input_go';
+ $this->config = new TestConfig();
+ $this->selenium = $selenium;
- public function setUp()
- {
- global $cfg;
- $this->cfg =& $cfg;
- //PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
-
- $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
-
- $this->start();
}
- public function tearDown()
- {
- $this->stop();
+ /**
+ * perform a login
+ * @param $username
+ * @param $password
+ */
+ public function login($username, $password) {
+
+ $this->selenium->open($this->config->getLoginURL());
+ $this->selenium->type($this->txtUsername, $username);
+ $this->selenium->type($this->txtPassword, $password);
+ $this->selenium->click($this->btnLogin);
+ $this->selenium->waitForPageToLoad($this->config->getTimeoutValue());
+
}
/**
- * perform a login
+ *
+ * @return boolean
*/
- public function doLogin()
- {
- $this->open(TESTSUITE_PHPMYADMIN_URL);
- // Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
- //$this->select("lang", "label=English");
-
- $this->waitForPageToLoad("30000");
- $this->type("input_username", TESTSUITE_USER);
- $this->type("input_password", TESTSUITE_PASSWORD);
- $this->click("input_go");
- $this->waitForPageToLoad("30001");
+ public function isSuccessLogin() {
+ if($this->selenium->isElementPresent("//*[@id=\"serverinfo\"]")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @return boolean
+ */
+ public function isUnsuccessLogin() {
+ $val = $this->selenium->getValue('input_go');
+ if($this->selenium->isElementPresent("//html/body/div/div[@class='error']")){
+ return true;
+ } else {
+ return false;
+ }
}
- /*
- * Just a dummy to show some example statements
- *
- public function mockTest()
- {
- // Slow down the testing speed, ideal for debugging
- //$this->setSpeed(4000);
-}
- */
}
?>
diff --git a/test/selenium/README b/test/selenium/README
new file mode 100644
index 0000000000..c13ee55e22
--- /dev/null
+++ b/test/selenium/README
@@ -0,0 +1,19 @@
+Guide to run the AllSeleniumTests.php (Yasitha Pandithawatta)
+=====================================
+
+1. Tested with version 4.0
+2. Configure the testing environment - Browser and the following feilds in phpunit.xml.dist
+
+
+
+
+
+
+
+
+3. Start the selenium server
+4. run $ phpunit test/AllSeleniumTests.php
+
+Note: Only PmaSeleniumLoginTest.php is fixed and added to the test suit.
+
+
diff --git a/test/selenium/TestConfig.php b/test/selenium/TestConfig.php
new file mode 100644
index 0000000000..4d2963c1ff
--- /dev/null
+++ b/test/selenium/TestConfig.php
@@ -0,0 +1,52 @@
+load('phpunit.xml.dist');
+ $searchNode = $xmlDoc->getElementsByTagName("browser");
+ foreach ($searchNode as $searchNode) {
+ $this->setCurrentBrowser($searchNode->getAttribute('browser'));
+ $this->setTimeoutValue($searchNode->getAttribute('timeout'));
+ }
+ $this->setLoginURL(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
+ }
+
+ public function setLoginURL($value) {
+
+ $this->loginURL = $value;
+ }
+
+ public function getLoginURL() {
+
+ return $this->loginURL;
+ }
+
+ public function setTimeoutValue($value) {
+
+ $this->timeoutValue = $value;
+ }
+
+ public function getTimeoutValue() {
+
+ return $this->timeoutValue;
+ }
+
+ public function setCurrentBrowser($value) {
+
+ $this->currentBrowser = $value;
+ }
+
+ public function getCurrentBrowser() {
+
+ return $this->currentBrowser;
+ }
+
+}
+
+?>